Ejemplo n.º 1
0
        //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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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;
                }
            }
        }
Ejemplo n.º 4
0
        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
            };
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        //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);
        }