public void AddMale(Males male) { using (var context = new RabbitsDBEntities()) { if (IsNameExist(male.Name, context)) throw new InvalidOperationException(AlreadyExist); context.Males.Add(male); context.SaveChanges(); } }
public void UpdateMale(Males male) { using (var context = new RabbitsDBEntities()) { if (IsNameExist(male.Name, context)) throw new InvalidOperationException(AlreadyExist); var result = context.Males.FirstOrDefault(x => x.Id == male.Id); if (result == null) throw new InvalidOperationException(NotFound); result.Name = male.Name; context.SaveChanges(); } }
public ActionResult UpdateMale(Males male) { try { if (ModelState.IsValid) { new MalesManager().UpdateMale(male); } return RedirectToAction(ShowMalesAction); } catch (InvalidOperationException exception) { return RedirectToAction(ErrorAction, new { exception }); } }
public void UpdateMale(Males male) { new MalesRepository().UpdateMale(male); }
public void AddMale(Males male) { new MalesRepository().AddMale(male); }