public static make MapCarMakeForCreate(CarMakeModel model)
        {
            var entity = new make();

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

                return(View(model));
            }
        }
        public ActionResult Edit(int id, CarMakeModel model)
        {
            using (log4net.NDC.Push("Post for editing car make"))
            {
                if (ModelState.IsValid)
                {
                    _logger.Info("Model is valid, search for make in the database" + id);
                    _logger.Info(model);
                    var entity = _entities.makes.FirstOrDefault(x => x.id == id);
                    if (entity == null)
                    {
                        _logger.Warn("Make not found");
                        return(new HttpNotFoundResult());
                    }

                    _logger.Info("Make found, updating the database entity");
                    MvcModelToDatabaseModelMapper.MapCarMakeForEdit(model, entity);
                    try
                    {
                        _entities.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        _logger.Warn("Make could not be updated", ex);
                        return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                    }
                    return(RedirectToAction("Index"));
                }
                return(View(model));
            }
        }
        // GET:  Makes/Create
        public ActionResult Create()
        {
            var model = new CarMakeModel
            {
                SortOrder = (_entities.makes.Max(x => x.SortOrder) ?? 0) + 100
            };

            return(View(model));
        }
 public static void MapCarMakeForEdit(CarMakeModel model, make entity)
 {
     entity.Name      = model.Name.Trim();
     entity.SortOrder = model.SortOrder;
 }
 public async Task AddCar(CarMakeModel carMake)
 {
     await _carMakeStore.InsertOneAsync(carMake);
 }
        public async Task <string> AddCarMake([FromBody] CarMakeModel carMake)
        {
            await _repo.AddCar(carMake);

            return(carMake.CarMake);
        }