Example #1
0
        public ActionResult Edit(IMProduct model)
        {
            //Static value used because CurrentPlantId is throwing exception
            model.PlantId = CurrentPlantId;
            if (ModelState.IsValid)
            {
                IMProductDto dto = Mapper.Map <IMProduct, IMProductDto>(model);

                //TODO: move to service
                using (var service = new IMProductService())
                {
                    if (model.Id > 0)
                    {
                        service.Update(dto);
                    }
                    else
                    {
                        service.Add(dto);
                    }
                }
                SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Please enter required fields.");
                SetResponseMesssage(ActionTypeMessage.FailedSave);

                return(View(model));
            }
            return(RedirectToAction("Edit"));
        }
Example #2
0
        public JsonResult GetByPlantResult()
        {
            List <IMProduct> products = new List <IMProduct>();

            using (IMProductService svc = new IMProductService())
            {
                var dtos = svc.GetByPlant(CurrentPlantId);
                products.AddRange(Mapper.Map <List <IMProductDto>, List <IMProduct> >(dtos));
            }
            return(Json(products, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public ActionResult Edit(int id = 0)
        {
            if (id == 0)
            {
                return(View(new IMProduct()));
            }
            using (var service = new IMProductService())
            {
                IMProduct model =
                    Mapper.Map <IMProductDto, IMProduct>(service.Get(id));

                return(View(model));
            }
        }