Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Sakalou.Module._9.OnlineShop;
- using Exceptions;
- namespace DataAccess
- {
- public class RepositoryDictionary : IRepository<Product>
- {
- private readonly Dictionary<int, Product> _data;
- public RepositoryDictionary(Dictionary<int, Product> data)
- {
- _data = data;
- }
- public void Create(Product obj)
- {
- _data.Add(obj.Id, obj);
- }
- public Product Read(int id)
- {
- return _data[id];
- }
- public void Update(Product obj)
- {
- if (!_data.ContainsValue(obj))
- {
- throw new NoItemException("There is no item with this id in data base");
- }
- }
- public void Delete(int id)
- {
- try
- {
- _data.Remove(id);
- }
- catch (KeyNotFoundException e)
- {
- throw new NoItemException("There is no item with this id in data base", e);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment