示例#1
0
 public void EditModel(VehicleModelVM VehicleModelVM)
 {
     //  db.Entry(Mapper.Map<VehicleModel>(VehicleModelVM)).State = EntityState.Modified;
     // db.SaveChanges();
     db.Set <VehicleModel>().AddOrUpdate(Mapper.Map <VehicleModel>(VehicleModelVM));
     db.SaveChanges();
 }
示例#2
0
 public IActionResult Create(VehicleModelVM model)
 {
     try
     {
         var modelForCreation = mapper.Map <Model>(model);
         if (ModelState.IsValid)
         {
             modelService.Create(modelForCreation);
             return(RedirectToAction("Detail", "Model", new { id = modelForCreation.Id }));
         }
         else
         {
             var createModel = new CreateModel
             {
                 Abrv           = model.Abrv,
                 MakeId         = model.MakeId,
                 DetailMakeName = model.DetailMakeName
             };
             return(View(createModel));
         }
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
示例#3
0
 public async Task <IHttpActionResult> CreateVehicleModelAsync(VehicleModelVM vehicleModel)
 {
     if (ModelState.IsValid)
     {
         await _vehicleModelService.AddVehicleModelAsync(Mapper.Map <VehicleModel>(vehicleModel));
     }
     return(Ok(vehicleModel));
 }
 public ActionResult Edit([Bind(Include = "Id,IdVehicleMake,Name,Abrv")] VehicleModelVM vehicleModelVM)
 {
     if (ModelState.IsValid)
     {
         VehicleService.GetInstance().EditModel(vehicleModelVM);
         return(RedirectToAction("Index"));
     }
     return(View(vehicleModelVM));
 }
示例#5
0
 public IActionResult Update(VehicleModelVM model)
 {
     try
     {
         modelService.Update(mapper.Map <Model>(model));
         return(RedirectToAction("Detail", "Model", new { id = model.Id }));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
示例#6
0
        public async Task <IHttpActionResult> DeleteVehicleModelAsync(int?id)
        {
            VehicleModelVM vehicleModelVM = Mapper.Map <VehicleModelVM>(await _vehicleModelService.GetVehicleModelAsync((int)id));

            if (vehicleModelVM == null)
            {
                return(NotFound());
            }
            await _vehicleModelService.DeleteVehicleModelAsync((int)id);

            return(Ok(vehicleModelVM));
        }
        /// <summary>
        /// Post method,
        /// api/VehicleModel
        /// </summary>
        /// <param name="VM">View Model, type of VehicleModelVM</param>
        public async Task <IHttpActionResult> Post([FromBody] VehicleModelVM VM)
        {
            try
            {
                await service.AddVehicleModelAsync(AutoMapper.Mapper.Map <IVehicleModel>(VM));

                return(Ok());
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Something went wrong can't create VehicleModel");
                return(InternalServerError());
            }
        }
示例#8
0
 public IActionResult Add(VehicleModelVM vehicleModel)
 {
     if (ModelState.IsValid)
     {
         var vh = mapper.Map <project.service.Models.VehicleModel>(vehicleModel);
         _vehicleModel.Add(vh);
         this.StatusCode(200);
     }
     else
     {
         this.StatusCode(400);
     }
     return(RedirectToAction("index"));
 }
示例#9
0
        public async Task <IHttpActionResult> UpdateVehicleModelAsync(int id, VehicleModelVM vehicleModel)
        {
            if (ModelState.IsValid)
            {
                await _vehicleModelService.UpdateVehicleModelAsync(Mapper.Map <VehicleModel>(vehicleModel));
            }
            if (id != vehicleModel.Id)
            {
                return(BadRequest());
            }

            if (vehicleModel == null)
            {
                return(NotFound());
            }
            return(Ok(vehicleModel));
        }
示例#10
0
 public ActionResult Edit(VehicleModelVM obj)
 {
     if (ModelState.IsValid)
     {
         string str = repository.EditModel(obj);
         if (str == "Ok")
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View());
         }
     }
     else
     {
         return(View());
     }
 }
        public async Task <IHttpActionResult> Put(int?id, [FromBody] VehicleModelVM VM)
        {
            try
            {
                if (id == null)
                {
                    return(BadRequest());
                }
                var success = await service.UpdateVehicleModelAsync(AutoMapper.Mapper.Map <IVehicleModel>(VM));

                if (!success)
                {
                    return(BadRequest());
                }
                return(Ok());
            }
            catch
            {
                ModelState.AddModelError("", "Something went wrong can't update VehicleModel");
                return(InternalServerError());
            }
        }
示例#12
0
        public string EditModel(VehicleModelVM item)
        {
            string result = string.Empty;

            try
            {
                var m = dbContext.Models.FirstOrDefault(x => x.Id == item.Id);
                if (m != null)
                {
                    m.Name   = item.Name;
                    m.MakeId = item.MakeId;
                    m.Abrv   = item.Abrv;
                    dbContext.SaveChanges();
                    result = "Ok";
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
示例#13
0
        public string AddModel(VehicleModelVM item)
        {
            string result = string.Empty;

            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            try
            {
                Mapper.CreateMap <VehicleModelVM, VehicleModel>();
                var m = Mapper.Map <VehicleModelVM, VehicleModel>(item);
                dbContext.Models.Add(m);
                dbContext.SaveChanges();
                result = "Ok";
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
示例#14
0
        /*   public IPagedList<VehicleMakeVM> FindMakeName(string search, int? page, string sortBy)
         * {
         *
         *
         *     return
         *
         * }
         * public IPagedList<VehicleMakeVM> FindMakeAbrv(string search, int? page)
         * {
         *     return
         *
         * }*/



        //Sad radim za model


        public void CreateModel(VehicleModelVM VehicleModelVM)
        {
            VehicleModelVM.Id = Guid.NewGuid();
            db.VehicleModels.Add(Mapper.Map <VehicleModel>(VehicleModelVM));
            db.SaveChanges();
        }