示例#1
0
 public async Task <IHttpActionResult> CreateVehicleMakeAsync(VehicleMakeVM vehicleMake)
 {
     if (ModelState.IsValid)
     {
         await _vehicleMakeService.AddVehicleMakeAsync(Mapper.Map <VehicleMake>(vehicleMake));
     }
     return(Ok(vehicleMake));
 }
示例#2
0
        public void EditMake(VehicleMakeVM VehicleMakeVM)
        {
            // db.Entry(Mapper.Map<VehicleMake>(VehicleMakeVM)).State = EntityState.Modified;
            //db.SaveChanges();

            db.Set <VehicleMake>().AddOrUpdate(Mapper.Map <VehicleMake>(VehicleMakeVM));
            db.SaveChanges();
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Abrv")] VehicleMakeVM vehicleMakeVM)
 {
     if (ModelState.IsValid)
     {
         VehicleService.GetInstance().EditMake(vehicleMakeVM);
         return(RedirectToAction("Index"));
     }
     return(View(vehicleMakeVM));
 }
示例#4
0
        public async Task <IHttpActionResult> DeleteVehicleMakeAsync(int id)
        {
            VehicleMakeVM vehicleMake = Mapper.Map <VehicleMakeVM>(await _vehicleMakeService.GetVehicleMakeAsync((int)id));

            if (vehicleMake == null)
            {
                return(NotFound());
            }
            await _vehicleMakeService.DeleteVehicleMakeAsync((int)id);

            return(Ok(vehicleMake));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Abrv")] VehicleMakeVM vehicleMakeVM)
        {
            if (ModelState.IsValid)
            {
                VehicleService.GetInstance().CreateMake(vehicleMakeVM);
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Krivo unesen maker");
            }

            return(View(vehicleMakeVM));
        }
示例#6
0
        public async Task <IHttpActionResult> Post([FromBody] VehicleMakeVM VM)
        {
            try
            {
                await service.AddVehicleMakeAsync(AutoMapper.Mapper.Map <VehicleMake>(VM));

                return(Ok());
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Something went wrong with creating VehicleMake");
                return(InternalServerError());
            }
        }
示例#7
0
        public IActionResult Update(VehicleMakeVM make)
        {
            try
            {
                Make makeForupdate = mapper.Map <Make>(make);
                makeService.Update(makeForupdate);
                makeService.UpdateModels(makeForupdate);

                return(RedirectToAction("Detail", "Make", new { id = make.Id }));
            }
            catch (Exception e)
            {
                return(BadRequest("Something went wrong" + e));
            }
        }
示例#8
0
        // (Create Page) selects a single record from the Makes table.
        // GET: /Model/Create?makeId
        public async Task <IActionResult> Create(int?makeId)
        {
            ViewData["Title"] = "Models | Create | ";

            VehicleMakeVM makeForModel = mapper.Map <VehicleMakeVM>(await modelService.GetMakeAsync(makeId));

            var createModel = new CreateModel
            {
                Abrv           = makeForModel.Abrv,
                MakeId         = makeForModel.Id,
                DetailMakeName = makeForModel.Name
            };

            return(View(createModel));
        }
示例#9
0
        public IEnumerable <VehicleMakeVM> GetAllVehicleMakes()
        {
            Mapper.CreateMap <VehicleMake, VehicleMakeVM>();
            var makesList = from make in dbContext.Makes select make;
            var makes     = new List <VehicleMakeVM>();

            if (makesList.Any())
            {
                foreach (var make in makesList)
                {
                    VehicleMakeVM makeModel = Mapper.Map <VehicleMake, VehicleMakeVM>(make);
                    makes.Add(makeModel);
                }
            }
            return(makes);
        }
示例#10
0
        public async Task <IHttpActionResult> UpdateVehicleMakeAsync(int id, VehicleMakeVM vehicleMake)
        {
            if (ModelState.IsValid)
            {
                await _vehicleMakeService.UpdateVehicleMakeAsync(Mapper.Map <VehicleMake>(vehicleMake));
            }
            if (id != vehicleMake.Id)
            {
                return(BadRequest());
            }

            if (vehicleMake == null)
            {
                return(NotFound());
            }
            return(Ok(vehicleMake));
        }
示例#11
0
        public ActionResult Create(VehicleMakeVM obj)
        {
            if (ModelState.IsValid)
            {
                string str = repository.AddMake(obj);
                if (str == "Ok")
                {
                    return(RedirectToAction("Index"));
                }
                return(View()); // open error page
            }

            else
            {
                return(View());
            }
        }
示例#12
0
        public IActionResult Create(VehicleMakeVM make)
        {
            try
            {
                var makeForCreation = mapper.Map <Make>(make);
                if (ModelState.IsValid)
                {
                    makeService.Create(makeForCreation);

                    return(RedirectToAction("Detail", "Make", new { id = makeForCreation.Id }));
                }

                return(View());
            }
            catch (Exception e)
            {
                return(BadRequest("Something went wrong     " + e));
            }
        }
示例#13
0
        public string EditMake(VehicleMakeVM item)
        {
            string result = string.Empty;

            try
            {
                var make = dbContext.Makes.FirstOrDefault(x => x.Id == item.Id);
                if (make != null)
                {
                    make.Name = item.Name;
                    make.Abrv = item.Abrv;
                    dbContext.SaveChanges();
                    result = "Ok";
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
示例#14
0
        public async Task <IHttpActionResult> Put(int?id, [FromBody] VehicleMakeVM VM)
        {
            try
            {
                if (id == null)
                {
                    return(BadRequest());
                }
                var success = await service.UpdateVehicleMakeAsync(AutoMapper.Mapper.Map <IVehicleMake>(VM));

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

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

            try
            {
                Mapper.CreateMap <VehicleMakeVM, VehicleMake>();
                var make = Mapper.Map <VehicleMakeVM, VehicleMake>(item);
                dbContext.Makes.Add(make);
                dbContext.SaveChanges();
                result = "Ok";
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
示例#16
0
 public void CreateMake(VehicleMakeVM VehicleMakeVM)
 {
     VehicleMakeVM.Id = Guid.NewGuid();
     db.VehiclMakes.Add(Mapper.Map <VehicleMake>(VehicleMakeVM));
     db.SaveChanges();
 }