示例#1
0
 public ActionResult Create(MobileViewModel mobileViewModel)
 {
     try
     {
         ViewBag.brands = new SelectList(brandBL.GetBrand(), "BrandId", "BrandName");
         if (ModelState.IsValid)
         {
             var config = new MapperConfiguration(mapping =>
             {
                 mapping.CreateMap <MobileViewModel, Mobile>();
             });
             IMapper mapper = config.CreateMapper();
             var     mobile = mapper.Map <MobileViewModel, Mobile>(mobileViewModel);
             //Mobile mobile = new Mobile();
             ////mobile.BrandName = mobileViewModel.BrandName;
             //mobile.Id = mobileViewModel.Id;
             //mobile.BatteryCapacity = mobileViewModel.BatteryCapacity;
             //mobile.Color = mobileViewModel.Color;
             //mobile.DisplaySize = mobileViewModel.DisplaySize;
             //mobile.MobileModel = mobileViewModel.MobileModel;
             //mobile.Pixel = mobileViewModel.Pixel;
             //mobile.Price = mobileViewModel.Price;
             //mobile.Processor = mobileViewModel.Processor;
             //mobile.RAM = mobileViewModel.RAM;
             //mobile.Slimness = mobileViewModel.Slimness;
             //mobile.Storage = mobileViewModel.Storage;
             mobileBL.CreateMobile(mobile);
             ViewBag.Message = "Mobile details added";
             ModelState.Clear();
             return(RedirectToAction("Display"));
         }
         else
         {
             ModelState.AddModelError("", "Some error occurred");
             return(View(mobileViewModel));
         }
     }
     catch
     {
         return(RedirectToAction("Error", "Error"));
     }
 }