コード例 #1
0
ファイル: VendorController.cs プロジェクト: vic0626/nas-merk
        //create
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
                return AccessDeniedView();

            var model = new VendorModel();
            PrepareVendorModel(model, null, false);
            //default value
            model.Active = true;
            return View(model);
        }
コード例 #2
0
ファイル: VendorController.cs プロジェクト: vic0626/nas-merk
        public ActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var vendor = new Vendor();

                vendor.Name = model.Name;
                vendor.Email = model.Email;
                vendor.Description = model.Description;
                vendor.AdminComment = model.AdminComment;
                vendor.Active = model.Active;
                _vendorService.InsertVendor(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = vendor.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            PrepareVendorModel(model, null, true);
            return View(model);
        }
コード例 #3
0
ファイル: VendorController.cs プロジェクト: vic0626/nas-merk
        protected void PrepareVendorModel(VendorModel model, Vendor vendor, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            if (vendor != null)
            {
                model.Id = vendor.Id;
                model.AssociatedCustomerEmails = _customerService
                    .GetAllCustomers(vendorId: vendor.Id)
                    .Select(c => c.Email)
                    .ToList();
                if (!excludeProperties)
                {
                    model.Name = vendor.Name;
                    model.Email = vendor.Email;
                    model.Description = vendor.Description;
                    model.AdminComment = vendor.AdminComment;
                    model.Active = vendor.Active;
                }
            }
        }
コード例 #4
0
ファイル: VendorController.cs プロジェクト: vic0626/nas-merk
        public ActionResult List(GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
                return AccessDeniedView();

            var vendors = _vendorService.GetAllVendors(command.Page - 1, command.PageSize, true);
            var gridModel = new GridModel<VendorModel>
            {
                Data = vendors.Select(x =>
                {
                    var m = new VendorModel();
                    PrepareVendorModel(m, x, false);
                    return m;
                }),
                Total = vendors.TotalCount,
            };
            return new JsonResult
            {
                Data = gridModel
            };
        }
コード例 #5
0
ファイル: VendorController.cs プロジェクト: vic0626/nas-merk
        public ActionResult Edit(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
                return AccessDeniedView();

            var vendor = _vendorService.GetVendorById(model.Id);
            if (vendor == null || vendor.Deleted)
                //No vendor found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                vendor.Name = model.Name;
                vendor.Email = model.Email;
                vendor.Description = model.Description;
                vendor.AdminComment = model.AdminComment;
                vendor.Active = model.Active;
                _vendorService.UpdateVendor(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Updated"));
                return continueEditing ? RedirectToAction("Edit", vendor.Id) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            PrepareVendorModel(model, vendor, true);
            return View(model);
        }
コード例 #6
0
ファイル: VendorController.cs プロジェクト: vic0626/nas-merk
        //edit
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
                return AccessDeniedView();

            var vendor = _vendorService.GetVendorById(id);
            if (vendor == null || vendor.Deleted)
                //No vendor found with the specified id
                return RedirectToAction("List");

            var model = new VendorModel();
            PrepareVendorModel(model, vendor, false);
            return View(model);
        }