public void Delete(long id) { if (id <= 0) { throw new ArgumentOutOfRangeException(nameof(id)); } _levelRepository.Delete(id); }
public string Edit(FormDataCollection form) { var retVal = string.Empty; var operation = form.Get("oper"); var id = ConvertHelper.ToInt32(form.Get("LevelId")); if (!string.IsNullOrEmpty(operation)) { LevelInfo info; switch (operation) { case "edit": info = LevelRepository.GetInfo(id); if (info != null) { info.Name = form.Get("Name"); info.Description = form.Get("Description"); info.Priority = ConvertHelper.ToInt32(form.Get("Priority")); info.ChangedBy = UserRepository.GetCurrentUserInfo().UserID; LevelRepository.Update(info); } break; case "add": info = new LevelInfo { Name = form.Get("Name"), Description = form.Get("Description"), Priority = ConvertHelper.ToInt32(form.Get("Priority")), CreatedBy = UserRepository.GetCurrentUserInfo().UserID }; LevelRepository.Create(info); break; case "del": LevelRepository.Delete(id, UserRepository.GetCurrentUserInfo().UserID); break; } } //StoreData._listLevel = LevelRepository.GetAll(); return(retVal); }
public void Should_Delete_Level_In_Db() { var fakeContext = new FakeContext("DeleteLevel"); fakeContext.FillWith <Level>(); using (var context = new MainContext(fakeContext.FakeOptions)) { var repository = new LevelRepository(context); var currentCount = context.Level.Count(); var newLevel = new Level(); newLevel.Name = "Testing"; context.Level.Add(newLevel); context.SaveChanges(); var idToDelete = (from l in context.Level.ToList() where l.Id == newLevel.Id select l.Id).FirstOrDefault(); Assert.Equal(currentCount + 1, context.Level.Count()); repository.Delete(idToDelete); Assert.Equal(currentCount, context.Level.Count()); repository.Dispose(); } }
public bool Delete(int Id) { LevelRepository repo = new LevelRepository(); return(repo.Delete(Id)); }