/// <summary> /// Add new request for unblocking account. /// </summary> /// <param name="id">id of account to unblock</param> /// <param name="userId">id of current user</param> public static void AddRequest(long id, string userId, IRepositoryFactory factory) { var account = factory.AccountRepository.FindById(id); if (account == null) throw new ValidationException("Нельзя разблокировать чужой счет"); if (account.User.Id != userId) throw new ValidationException("Нельзя разблокировать чужой счет"); if(!account.IsBlocked) throw new ValidationException("Аккаунт не заблокирован."); var oldRequest = factory.RequestRepository.Find(r => r.Account.AccountId == id).FirstOrDefault(); if (oldRequest == null) { var request = new Request { Account = account, Date = DateTime.Now }; factory.RequestRepository.Add(request); } else { oldRequest.Date = DateTime.Now; factory.RequestRepository.Edit(oldRequest); } }
public void Edit(Request item) { _db.Entry(item).State = EntityState.Modified; _db.SaveChanges(); }
public void Add(Request item) { _db.Requests.Add(item); _db.SaveChanges(); }