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_Save_New_Level_To_Db() { var fakeContext = new FakeContext("AddNewLevel"); var fakeLevel = new Level(); fakeLevel.Name = "Desenvolvimento"; fakeLevel.Id = 4; using (var context = new MainContext(fakeContext.FakeOptions)) { var repository = new LevelRepository(context); repository.Create(fakeLevel); var createdLevel = repository.GetById(4); Assert.NotEqual(0, fakeLevel.Id); Assert.Equal("Desenvolvimento", createdLevel.Name); Assert.Equal(4, createdLevel.Id); repository.Dispose(); } }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here try { //fill business object var info = new LevelInfo(); /* * * * info.LevelId = collection["LevelId"]; * * * * info.Name = collection["Name"]; * * * * * info.Description = collection["Description"]; * * * * * * info.Priority = collection["Priority"]; * * * * * info.CreatedBy = collection["CreatedBy"]; * * * * * * * * * * info.ChangedBy = collection["ChangedBy"]; * * * * * * * * */ LevelRepository.Create(info); } catch (Exception ex) { } return(RedirectToAction("Index")); } catch { return(View()); } }