public ActionResult Edit(HistoryEdit historyEdit) { if (Request.IsAuthenticated) { try { History history = db.Histories.Find(historyEdit.HistoryId); history.Edit(historyEdit); if (ModelState.IsValid) { db.Entry(history).State = EntityState.Modified; db.SaveChanges(); return(View("Details", history)); } return(View(historyEdit)); } catch { return(HttpNotFound()); } } else { return(Redirect(Url.Action("Login", "Account"))); } }
public ActionResult Edit(int id, HistoryEdit model) { var animalService = new AnimalService(); var caretakerService = new CaretakerService(); var animalList = animalService.GetAnimals(); var caretakerList = caretakerService.GetCaretakers(); ViewBag.AnimalID = new SelectList(animalList, "AnimalID", "AnimalName"); ViewBag.CaretakerID = new SelectList(caretakerList, "CaretakerID", "CaretakerName"); if (!ModelState.IsValid) { return(View(model)); } if (model.HistoryID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = new HistoryService(); if (service.UpdateHistory(model)) { TempData["SaveResult"] = "Your History Entry was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your History Entry could not be updated."); return(View()); }
public ActionResult Edit(int id) { var animalService = new AnimalService(); var caretakerService = new CaretakerService(); var animalList = animalService.GetAnimals(); var caretakerList = caretakerService.GetCaretakers(); ViewBag.AnimalID = new SelectList(animalList, "AnimalID", "AnimalName"); ViewBag.CaretakerID = new SelectList(caretakerList, "CaretakerID", "CaretakerName"); var service = new HistoryService(); var detail = service.GetHistoryByID(id); var model = new HistoryEdit { HistoryID = detail.HistoryID, AnimalID = detail.AnimalID, CaretakerID = detail.CaretakerID, AnimalName = detail.AnimalName, CaretakerName = detail.CaretakerName, HistoryCareType = detail.HistoryCareType, DateOfCareStart = detail.DateOfCareStart }; return(View(model)); }
public void InitHistories() { Applicant = new ApplicantWeb.Models.Applicant(); HistoryFields = new HistoryFields(new DateTime(2015, 09, 15), ApplicantClassLibrary.TypeHistory.Interview, "Здорово!!!"); HistoryCreate = new HistoryCreate(HistoryFields, Applicant.ApplicantId, Applicant); History = new History(HistoryCreate); HistoryEdit = new HistoryEdit(HistoryFields); }
public bool UpdateHistory(HistoryEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Histories .Single(h => h.HistoryID == model.HistoryID); entity.HistoryID = model.HistoryID; entity.AnimalID = model.AnimalID; entity.CaretakerID = model.CaretakerID; entity.HistoryCareType = model.HistoryCareType; entity.DateOfCareStart = model.DateOfCareStart; return(ctx.SaveChanges() == 1); }; }
public JsonResult Edit(HistoryEdit data) { int id; var ok = int.TryParse(data.Id, out id); if (!ok || id == 0) { return(Json("Bad ID")); } using (var db = new dbContext()) { var item = db.Sales_Histories.First(x => x.Id == id); if (item == null) { return(Json("Not found")); } try { Type type = item.GetType(); PropertyInfo prop = type.GetProperty(data.Field); var targetType = (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition().Equals(typeof(Nullable <>))) ? Nullable.GetUnderlyingType(prop.PropertyType) : prop.PropertyType; object newValue; newValue = Convert.ChangeType(data.Value, targetType); prop.SetValue(item, newValue, null); } catch (Exception e) { return(Json("Unexpected error on updating value " + e.Message)); } db.SaveChanges(); } return(Json("ok")); }