protected virtual void PrepareNhaXeModel(NhaXeModel model) { if (model == null) { throw new ArgumentNullException("model"); } var diachi = _diachiService.GetById(model.DiaChiID); model.ThongTinDiaChi = diachi.ToModel(); var states = _stateProvinceService.GetStateProvincesByCountryId(CountryID); if (states.Count > 0) { foreach (var s in states) { model.ThongTinDiaChi.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.ThongTinDiaChi.ProvinceID) }); } } if (model.DiaChiID > 0 && diachi.ProvinceID > 0) { var quanhuyens = _diachiService.GetQuanHuyenByProvinceId(diachi.ProvinceID); foreach (var s in quanhuyens) { model.ThongTinDiaChi.AvailableQuanHuyens.Add(new SelectListItem { Text = s.Ten, Value = s.Id.ToString(), Selected = (s.Id == model.ThongTinDiaChi.QuanHuyenID) }); } } }
public ActionResult SuaNhaXe(NhaXeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.QLNhaXe)) { return(AccessDeniedView()); } var nhaxe = _nhaxeService.GetNhaXeById(model.Id); if (nhaxe == null || nhaxe.isDelete) { //No manufacturer found with the specified id return(RedirectToAction("ListNhaXe")); } if (ModelState.IsValid) { int prevLogoID = nhaxe.LogoID; int prevAnhDaiDienID = nhaxe.AnhDaiDienID; //diachi.Id = nhaxe.DiaChiID; nhaxe = model.ToEntity(nhaxe); _nhaxeService.UpdateNhaXe(nhaxe); var diachi = _diachiService.GetById(nhaxe.DiaChiID); diachi = model.ThongTinDiaChi.ToEntity(diachi); diachi.Id = nhaxe.DiaChiID; _diachiService.Update(diachi); //delete an old picture (if deleted or updated) if (prevLogoID > 0 && prevLogoID != nhaxe.LogoID) { var prevPicture = _pictureService.GetPictureById(prevLogoID); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } if (prevAnhDaiDienID > 0 && prevAnhDaiDienID != nhaxe.AnhDaiDienID) { var prevPicture = _pictureService.GetPictureById(prevAnhDaiDienID); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("SuaNhaXe", nhaxe.Id)); } return(RedirectToAction("ListNhaXe")); } return(View(model)); }
public ActionResult TaoNhaXe(NhaXeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.QLNhaXe)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var nhaxe = model.ToEntity(); var diachi = model.ThongTinDiaChi.ToEntity(); _diachiService.Insert(diachi); nhaxe.DiaChiID = diachi.Id; nhaxe.NguoiTaoID = _workContext.CurrentCustomer.Id; _nhaxeService.InsertNhaXe(nhaxe); SuccessNotification(_localizationService.GetResource("Admin.chonve.nhaxe.themmoi")); return(continueEditing ? RedirectToAction("SuaNhaXe", new { id = nhaxe.Id }) : RedirectToAction("ListNhaXe")); } return(View(model)); }
public ActionResult TaoNhaXe() { if (!_permissionService.Authorize(StandardPermissionProvider.QLNhaXe)) { return(AccessDeniedView()); } var model = new NhaXeModel(); //default values var states = _stateProvinceService.GetStateProvincesByCountryId(CountryID); if (states.Count > 0) { foreach (var s in states) { model.ThongTinDiaChi.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.ThongTinDiaChi.ProvinceID) }); } } return(View(model)); }
public static NhaXe ToEntity(this NhaXeModel model, NhaXe destination) { return(model.MapTo(destination)); }
public static NhaXe ToEntity(this NhaXeModel model) { return(model.MapTo <NhaXeModel, NhaXe>()); }