Beispiel #1
0
        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));
        }
Beispiel #2
0
        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));
        }