public static carmodel MapCarModelForCreate(ModelForCarMakeModel model)
        {
            var entity = new carmodel();

            MapCarModelForEdit(model, entity);
            return(entity);
        }
        public ActionResult Create([Bind(Include = "Id,MakeId,Name,SortOrder")] ModelForCarMakeModel model)
        {
            using (log4net.NDC.Push("Create car model post"))
            {
                _logger.Info("Save car model");
                _logger.Info(model);
                if (ModelState.IsValid)
                {
                    _logger.Info("Model is valid, map to entity model");
                    var entityModel = MvcModelToDatabaseModelMapper.MapCarModelForCreate(model);
                    _entities.carmodels.Add(entityModel);
                    try
                    {
                        _entities.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        _logger.Warn("Saving of car model entity failed", ex);
                        return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                    }
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
        }
        public ActionResult Edit([Bind(Include = "Id,MakeId,Name,SortOrder")] ModelForCarMakeModel model)
        {
            using (log4net.NDC.Push("Edit Building POST"))
            {
                _logger.Info("Check if model is valid");
                if (ModelState.IsValid)
                {
                    _logger.Info("Model is valid, save model");
                    var entityRecord = _entities.carmodels.FirstOrDefault(x => x.Id == model.Id);
                    MvcModelToDatabaseModelMapper.MapCarModelForEdit(model, entityRecord);
                    try
                    {
                        _logger.Info("Save model");
                        _entities.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        _logger.Warn("model could not be updated", ex);
                        return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                    }

                    return(RedirectToAction("Index"));
                }
                _logger.Warn("Model is not valid, cannot save car model");

                return(View(model));
            }
        }
        // GET: Building/Create
        public ActionResult Create()
        {
            var model = new ModelForCarMakeModel();

            model.SortOrder = (_entities.carmodels.Max(x => x.SortOrder) ?? 0) + 100;
            MvcModelToDatabaseModelMapper.MapCarModelForCreate(model);
            PopulateCarModelsInViewBag(0);
            return(View(model));
        }
 public static void MapCarModelForEdit(ModelForCarMakeModel model, carmodel entity)
 {
     if (model.Name != null)
     {
         entity.Name = model.Name.Trim();
     }
     else
     {
         entity.Name = model.Name;
     }
     entity.SortOrder = model.SortOrder;
     entity.MakeId    = model.MakeId;
 }