public static infringementtype MapInfringementTypeForCreate(InfringementTypeModel model) { var entity = new infringementtype(); MapInfringementTypeForEdit(model, entity); return(entity); }
public ActionResult Create([Bind(Include = "Type,Amount,SortOrder")] InfringementTypeModel model) { using (log4net.NDC.Push("Create infrn. type post")) { _logger.Info("Save specific infringement type"); _logger.Info(model); if (ModelState.IsValid) { _logger.Info("Model is valid, map to entity model"); var entityModel = MvcModelToDatabaseModelMapper.MapInfringementTypeForCreate(model); _entities.infringementtypes.Add(entityModel); try { _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("Saving of infrin. type entity failed", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(model)); } }
public ActionResult Edit([Bind(Include = "Id,Type,Amount,SortOrder")] InfringementTypeModel model) { using (log4net.NDC.Push("Post for editing infrin. type")) { if (ModelState.IsValid) { _logger.Info("Model is valid, search for city in the database" + model.Id); _logger.Info(model); var entity = _entities.infringementtypes.FirstOrDefault(x => x.Id == model.Id); if (entity == null) { _logger.Warn("Infrin. type not found"); return(new HttpNotFoundResult()); } _logger.Info("Infrin. type found, updating the database entity"); MvcModelToDatabaseModelMapper.MapInfringementTypeForEdit(model, entity); try { _entities.SaveChanges(); } catch (Exception ex) { _logger.Warn("Infrin. type could not be updated", ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(RedirectToAction("Index")); } return(View(model)); } }
// GET: InfringementTypes/Create public ActionResult Create() { var model = new InfringementTypeModel { SortOrder = (_entities.infringementtypes.Max(x => x.SortOrder) ?? 0) + 100 }; return(View(model)); }
public static void MapInfringementTypeForEdit(InfringementTypeModel model, infringementtype entity) { entity.Type = model.Type; entity.SortOrder = model.SortOrder; entity.Amount = model.Amount; }