public virtual async Task <Vendor> UpdateVendorModel(Vendor vendor, VendorModel model)
        {
            string prevPictureId = vendor.PictureId;

            vendor         = model.ToEntity(vendor);
            vendor.Locales = await model.Locales.ToLocalizedProperty(vendor, x => x.Name, _seoSettings, _urlRecordService, _languageService);

            model.SeName = await vendor.ValidateSeName(model.SeName, vendor.Name, true, _seoSettings, _urlRecordService, _languageService);

            vendor.Address = model.Address.ToEntity(vendor.Address);

            //discounts
            var allDiscounts = await _discountService.GetAllDiscounts(DiscountType.AssignedToVendors, showHidden : true);

            foreach (var discount in allDiscounts)
            {
                if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
                {
                    //new discount
                    if (vendor.AppliedDiscounts.Count(d => d == discount.Id) == 0)
                    {
                        vendor.AppliedDiscounts.Add(discount.Id);
                    }
                }
                else
                {
                    //remove discount
                    if (vendor.AppliedDiscounts.Count(d => d == discount.Id) > 0)
                    {
                        vendor.AppliedDiscounts.Remove(discount.Id);
                    }
                }
            }

            vendor.SeName = model.SeName;

            await _vendorService.UpdateVendor(vendor);

            //search engine name
            await _urlRecordService.SaveSlug(vendor, model.SeName, "");

            //delete an old picture (if deleted or updated)
            if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != vendor.PictureId)
            {
                var prevPicture = await _pictureService.GetPictureById(prevPictureId);

                if (prevPicture != null)
                {
                    await _pictureService.DeletePicture(prevPicture);
                }
            }
            //update picture seo file name
            await _pictureService.UpdatePictureSeoNames(vendor.PictureId, vendor.Name);

            return(vendor);
        }
예제 #2
0
        public virtual ActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var vendor = model.ToEntity();
                _vendorService.InsertVendor(vendor);

                //activity log
                _customerActivityService.InsertActivity("AddNewVendor", _localizationService.GetResource("ActivityLog.AddNewVendor"), vendor.Id);

                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);

                //address
                var address = model.Address.ToEntity();
                address.CreatedOnUtc = DateTime.UtcNow;
                //some validation
                if (address.CountryId == 0)
                {
                    address.CountryId = null;
                }
                if (address.StateProvinceId == 0)
                {
                    address.StateProvinceId = null;
                }
                _addressService.InsertAddress(address);
                vendor.AddressId = address.Id;
                _vendorService.UpdateVendor(vendor);

                //locales
                UpdateLocales(vendor, model);
                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = vendor.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareVendorModel(model, null, true, true);
            return(View(model));
        }
예제 #3
0
        public IActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var vendor = model.ToEntity();
                vendor.Address = model.Address.ToEntity();
                vendor.Address.CreatedOnUtc = DateTime.UtcNow;

                _vendorService.InsertVendor(vendor);

                //discounts
                var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToVendors, showHidden: true);
                foreach (var discount in allDiscounts)
                {
                    if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
                    {
                        vendor.AppliedDiscounts.Add(discount.Id);
                    }
                }

                //search engine name
                model.SeName   = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                vendor.Locales = UpdateLocales(vendor, model);
                vendor.SeName  = model.SeName;
                _vendorService.UpdateVendor(vendor);

                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                _urlRecordService.SaveSlug(vendor, model.SeName, "");


                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = vendor.Id }) : RedirectToAction("List"));
            }
            //prepare address model
            PrepareVendorAddressModel(model, null);
            //discounts
            PrepareDiscountModel(model, null, true);
            //stores
            PrepareStore(model);

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #4
0
        public ActionResult Edit(VendorModel model, FormCollection frm, bool continueEditing)
        {
            if (!_permissionService.Authorize("ManageVendors"))
            {
                return(AccessDeniedView());
            }

            var user = _userContext.CurrentUser;
            // Check for duplicate vendor, if any
            var vendor = _smsService.GetVendorsByName(model.Name);

            if (vendor != null)
            {
                if (vendor.Id != model.Id)
                {
                    ModelState.AddModelError("Name", "An Vendor with the same name already exists. Please choose a different name.");
                }
            }

            if (ModelState.IsValid)
            {
                var selectVendor = _smsService.GetVendorById(model.Id);
                if (selectVendor == null || selectVendor.IsDeleted)
                {
                    return(RedirectToAction("List"));
                }

                selectVendor            = model.ToEntity(selectVendor);
                selectVendor.ModifiedOn = DateTime.Now;
                _smsService.UpdateVendor(selectVendor);
            }
            else
            {
                model.AvailableAcadmicYears = _smsService.GetAllAcadmicYears().Select(x => new SelectListItem()
                {
                    Text     = x.Name.Trim(),
                    Value    = x.Id.ToString(),
                    Selected = x.Id == model.AcadmicYearId
                }).ToList();
                ErrorNotification("An error occured while updating vendor. Please try again.");
                return(View(model));
            }

            SuccessNotification("Vendor updated successfully.");
            if (continueEditing)
            {
                return(RedirectToAction("Edit", new { id = model.Id }));
            }
            return(RedirectToAction("List"));
        }
예제 #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 = model.ToEntity(vendor);
                _vendorService.UpdateVendor(vendor);
                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);
                //locales
                UpdateLocales(vendor, model);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return(RedirectToAction("Edit", vendor.Id));
                }
                else
                {
                    return(RedirectToAction("List"));
                }
            }

            //If we got this far, something failed, redisplay form

            //associated customer emails
            model.AssociatedCustomerEmails = _customerService
                                             .GetAllCustomers(vendorId: vendor.Id)
                                             .Select(c => c.Email)
                                             .ToList();
            return(View(model));
        }
예제 #6
0
        public virtual IActionResult Create(VendorModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                model.VendorId     = Guid.NewGuid().ToString("N");
                model.VendorStatus = (int)Vendor.StatusEnum.New;
                var vendor = model.ToEntity();
                vendor.UpdatedOnUtc  = DateTime.UtcNow;
                vendor.CreatedOnUtc  = DateTime.UtcNow;
                vendor.CreatedUserId = _workContext.CurrentCustomer.CustomerId;
                vendor.UpdatedUserId = _workContext.CurrentCustomer.CustomerId;
                _vendorService.InsertVendor(vendor);

                //activity log
                _customerActivityService.InsertActivity("AddNewVendor", _localizationService.GetResource("ActivityLog.AddNewVendor"), vendor.Id);

                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.VendorName, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);

                //locales
                UpdateLocales(vendor, model);
                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added"));

                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareVendorModel(model, null, true, true);
            PrepareAllVendorStatus(model);
            return(View(model));
        }
        public ActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var vendor = model.ToEntity();

                //fill latitude and longitude from address
                if (vendor.StreetAddress != null && vendor.StreetAddress != "")
                {
                    var city = _cityService.GetCityById(vendor.CityId.Value);
                    vendor.StateId = city.StateId;
                    var state = _stateProvinceService.GetStateProvinceById(vendor.StateId.Value);
                    vendor.CountryId = state.CountryId;
                    GoogleLocationService locservice = new GoogleLocationService();
                    MapPoint point = locservice.GetLatLongFromAddress(vendor.StreetAddress + ", " + city.CityName + ", " + state.Abbreviation + " " + city.PostCode);
                    vendor.Latitude  = point.Latitude;
                    vendor.Longitude = point.Longitude;
                }

                _vendorService.InsertVendor(vendor);
                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);
                //locales
                UpdateLocales(vendor, model);

                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
            return(View(model));
        }
예제 #8
0
        public ActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var vendor = model.ToEntity();
                _vendorService.InsertVendor(vendor);
                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);
                //locales
                UpdateLocales(vendor, model);

                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
            return(View(model));
        }
예제 #9
0
        public virtual IActionResult Edit(VendorModel model, bool continueEditing, IFormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            //try to get a vendor with the specified id
            var vendor = _vendorService.GetVendorById(model.Id);

            if (vendor == null || vendor.Deleted)
            {
                return(RedirectToAction("List"));
            }

            //parse vendor attributes
            var vendorAttributesXml = ParseVendorAttributes(form);

            _vendorAttributeParser.GetAttributeWarnings(vendorAttributesXml).ToList()
            .ForEach(warning => ModelState.AddModelError(string.Empty, warning));

            if (ModelState.IsValid)
            {
                var prevPictureId = vendor.PictureId;
                vendor = model.ToEntity(vendor);
                _vendorService.UpdateVendor(vendor);

                //vendor attributes
                _genericAttributeService.SaveAttribute(vendor, NopVendorDefaults.VendorAttributes, vendorAttributesXml);

                //activity log
                _customerActivityService.InsertActivity("EditVendor",
                                                        string.Format(_localizationService.GetResource("ActivityLog.EditVendor"), vendor.Id), vendor);

                //search engine name
                model.SeName = _urlRecordService.ValidateSeName(vendor, model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);

                //address
                var address = _addressService.GetAddressById(vendor.AddressId);
                if (address == null)
                {
                    address = model.Address.ToEntity <Address>();
                    address.CreatedOnUtc = DateTime.UtcNow;

                    //some validation
                    if (address.CountryId == 0)
                    {
                        address.CountryId = null;
                    }
                    if (address.StateProvinceId == 0)
                    {
                        address.StateProvinceId = null;
                    }

                    _addressService.InsertAddress(address);
                    vendor.AddressId = address.Id;
                    _vendorService.UpdateVendor(vendor);
                }
                else
                {
                    address = model.Address.ToEntity(address);

                    //some validation
                    if (address.CountryId == 0)
                    {
                        address.CountryId = null;
                    }
                    if (address.StateProvinceId == 0)
                    {
                        address.StateProvinceId = null;
                    }

                    _addressService.UpdateAddress(address);
                }

                //locales
                UpdateLocales(vendor, model);

                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != vendor.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Vendors.Updated"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                return(RedirectToAction("Edit", new { id = vendor.Id }));
            }

            //prepare model
            model = _vendorModelFactory.PrepareVendorModel(model, vendor, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #10
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)
            {
                int prevPictureId = vendor.PictureId;
                vendor = model.ToEntity(vendor);
                _vendorService.UpdateVendor(vendor);

                //activity log
                _customerActivityService.InsertActivity("EditVendor", _localizationService.GetResource("ActivityLog.EditVendor"), vendor.Id);

                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);

                //address
                var address = _addressService.GetAddressById(vendor.AddressId);
                if (address == null)
                {
                    address = model.Address.ToEntity();
                    address.CreatedOnUtc = DateTime.UtcNow;
                    //some validation
                    if (address.CountryId == 0)
                        address.CountryId = null;
                    if (address.StateProvinceId == 0)
                        address.StateProvinceId = null;

                    _addressService.InsertAddress(address);
                    vendor.AddressId = address.Id;
                    _vendorService.UpdateVendor(vendor);
                }
                else
                {
                    address = model.Address.ToEntity(address);
                    //some validation
                    if (address.CountryId == 0)
                        address.CountryId = null;
                    if (address.StateProvinceId == 0)
                        address.StateProvinceId = null;

                    _addressService.UpdateAddress(address);
                }


                //locales
                UpdateLocales(vendor, model);
                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != vendor.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                        _pictureService.DeletePicture(prevPicture);
                }
                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return RedirectToAction("Edit",  new {id = vendor.Id});
                }
                return RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            PrepareVendorModel(model, vendor, true, true);

            return View(model);
        }
예제 #11
0
        public virtual IActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            //parse vendor attributes
            var vendorAttributesXml = ParseVendorAttributes(model.Form);

            _vendorAttributeParser.GetAttributeWarnings(vendorAttributesXml).ToList()
            .ForEach(warning => ModelState.AddModelError(string.Empty, warning));

            if (ModelState.IsValid)
            {
                var vendor = model.ToEntity <Vendor>();
                _vendorService.InsertVendor(vendor);

                //activity log
                _customerActivityService.InsertActivity("AddNewVendor",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewVendor"), vendor.Id), vendor);

                //search engine name
                model.SeName = _urlRecordService.ValidateSeName(vendor, model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);

                //address
                var address = model.Address.ToEntity <Address>();
                address.CreatedOnUtc = DateTime.UtcNow;

                //some validation
                if (address.CountryId == 0)
                {
                    address.CountryId = null;
                }
                if (address.StateProvinceId == 0)
                {
                    address.StateProvinceId = null;
                }
                _addressService.InsertAddress(address);
                vendor.AddressId = address.Id;
                _vendorService.UpdateVendor(vendor);

                //vendor attributes
                _genericAttributeService.SaveAttribute(vendor, NopVendorDefaults.VendorAttributes, vendorAttributesXml);

                //locales
                UpdateLocales(vendor, model);

                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("Edit", new { id = vendor.Id }));
            }

            //prepare model
            model = _vendorModelFactory.PrepareVendorModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        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)
            {
                int prevPictureId = vendor.PictureId;
                vendor = model.ToEntity(vendor);
                _vendorService.UpdateVendor(vendor);
                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);
                //locales
                UpdateLocales(vendor, model);
                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != vendor.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = vendor.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form

            //associated customer emails
            model.AssociatedCustomers = _customerService
                                        .GetAllCustomers(vendorId: vendor.Id)
                                        .Select(c => new VendorModel.AssociatedCustomerInfo()
            {
                Id    = c.Id,
                Email = c.Email
            })
                                        .ToList();

            return(View(model));
        }
예제 #13
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)
            {
                string prevPictureId = vendor.PictureId;
                vendor         = model.ToEntity(vendor);
                vendor.Locales = UpdateLocales(vendor, model);
                model.SeName   = vendor.ValidateSeName(model.SeName, vendor.Name, true);

                //discounts
                var allDiscounts = _discountService.GetAllDiscounts(DiscountType.AssignedToVendors, showHidden: true);
                foreach (var discount in allDiscounts)
                {
                    if (model.SelectedDiscountIds != null && model.SelectedDiscountIds.Contains(discount.Id))
                    {
                        //new discount
                        if (vendor.AppliedDiscounts.Count(d => d.Id == discount.Id) == 0)
                        {
                            vendor.AppliedDiscounts.Add(discount);
                        }
                    }
                    else
                    {
                        //remove discount
                        if (vendor.AppliedDiscounts.Count(d => d.Id == discount.Id) > 0)
                        {
                            vendor.AppliedDiscounts.Remove(discount);
                        }
                    }
                }

                vendor.SeName = model.SeName;

                _vendorService.UpdateVendor(vendor);
                //search engine name
                _urlRecordService.SaveSlug(vendor, model.SeName, "");

                //delete an old picture (if deleted or updated)
                if (!String.IsNullOrEmpty(prevPictureId) && prevPictureId != vendor.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                //update picture seo file name
                UpdatePictureSeoNames(vendor);


                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return(RedirectToAction("Edit", new { id = vendor.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            //discounts
            PrepareDiscountModel(model, vendor, true);

            //associated customer emails
            model.AssociatedCustomers = _customerService
                                        .GetAllCustomers(vendorId: vendor.Id)
                                        .Select(c => new VendorModel.AssociatedCustomerInfo()
            {
                Id    = c.Id,
                Email = c.Email
            })
                                        .ToList();

            return(View(model));
        }
예제 #14
0
        public ActionResult Edit(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)
                 && !_permissionService.Authorize(StandardPermissionProvider.ManageVendor) //add by hz
                )
                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)
            {
                int prevPictureId = vendor.PictureId;
                vendor = model.ToEntity(vendor);
                vendor.UpdatedOnUtc = DateTime.UtcNow;
                _vendorService.UpdateVendor(vendor);
                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);
                //locales
                UpdateLocales(vendor, model);
                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != vendor.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                        _pictureService.DeletePicture(prevPicture);
                }
                //update picture seo file name
                UpdatePictureSeoNames(vendor);
                //acl
                SaveVendorAcl(vendor, model);

                //activity log
                _customerActivityService.InsertActivity("EditVendor", _localizationService.GetResource("ActivityLog.EditVendor"), vendor.Name);

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

            //If we got this far, something failed, redisplay form
            //templates
            PrepareTemplatesModel(model);
            //Acl
            PrepareAclModel(model, vendor, true);

            return View(model);
        }
예제 #15
0
        public ActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();
            if (customerVendorId > 0)
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var vendor = model.ToEntity();
                vendor.CreatedOnUtc = DateTime.UtcNow;
                vendor.UpdatedOnUtc = DateTime.UtcNow;
                _vendorService.InsertVendor(vendor);
                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);
                //locales
                UpdateLocales(vendor, model);
                //update picture seo file name
                UpdatePictureSeoNames(vendor);
                //ACL (customer roles)
                SaveVendorAcl(vendor, model);
                //activity log
                _customerActivityService.InsertActivity("AddNewVendor", _localizationService.GetResource("ActivityLog.AddNewVendor"), vendor.Name);

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

            //If we got this far, something failed, redisplay form
            //templates
            PrepareTemplatesModel(model);
            //ACL
            PrepareAclModel(model, null, true);
            return View(model);
        }
예제 #16
0
        public virtual IActionResult Edit(VendorModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            var vendor = _vendorService.GetVendorById(model.VendorId);

            if (vendor == null || vendor.VendorStatus == (int)Vendor.StatusEnum.Deleted)
            {
                //No vendor found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                //var prevPictureId = vendor.PictureId;
                vendor = model.ToEntity(vendor);
                vendor.UpdatedOnUtc  = DateTime.UtcNow;
                vendor.UpdatedUserId = _workContext.CurrentCustomer.CustomerId;

                _vendorService.UpdateVendor(vendor);

                //activity log
                _customerActivityService.InsertActivity("EditVendor", _localizationService.GetResource("ActivityLog.EditVendor"), vendor.Id);

                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.VendorName, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);

                //address
                //var address = _addressService.GetAddressById(vendor.AddressId);
                //if (address == null)
                //{
                //    address = model.Address.ToEntity();
                //    address.CreatedOnUtc = DateTime.UtcNow;
                //    //some validation
                //    if (address.CountryId == 0)
                //        address.CountryId = null;
                //    if (address.StateProvinceId == 0)
                //        address.StateProvinceId = null;

                //    _addressService.InsertAddress(address);
                //    vendor.AddressId = address.Id;
                //    _vendorService.UpdateVendor(vendor);
                //}
                //else
                //{
                //    address = model.Address.ToEntity(address);
                //    //some validation
                //    if (address.CountryId == 0)
                //        address.CountryId = null;
                //    if (address.StateProvinceId == 0)
                //        address.StateProvinceId = null;

                //    _addressService.UpdateAddress(address);
                //}


                //locales
                UpdateLocales(vendor, model);
                //delete an old picture (if deleted or updated)
                //if (prevPictureId > 0 && prevPictureId != vendor.PictureId)
                //{
                //    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                //    if (prevPicture != null)
                //        _pictureService.DeletePicture(prevPicture);
                //}
                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Updated"));

                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareVendorModel(model, vendor, true, true);
            PrepareAllVendorStatus(model);

            return(View(model));
        }
예제 #17
0
        public virtual ActionResult Create(VendorModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var cust1 = _customerService.GetCustomerByEmail(model.Email);
                if (cust1 != null)
                {
                    ModelState.AddModelError("Email", "Email is already registered");
                }

                var cust2 = _customerService.GetCustomerByUsername(model.AccountId);
                if (cust2 != null)
                {
                    ModelState.AddModelError("AccountId", "Vendor account ID is already registered");
                }

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var vendor = model.ToEntity();
                _vendorService.InsertVendor(vendor);

                var customer = new Customer
                {
                    CustomerGuid        = Guid.NewGuid(),
                    Email               = model.Email,
                    Username            = model.AccountId,
                    VendorId            = vendor.Id,
                    AdminComment        = model.AdminComment,
                    Active              = model.Active,
                    CreatedOnUtc        = DateTime.UtcNow,
                    LastActivityDateUtc = DateTime.UtcNow,
                    RegisteredInStoreId = 0
                };
                _customerService.InsertCustomer(customer);
                var allCustomerRoles = _customerService.GetAllCustomerRoles(true);
                //customer roles
                foreach (var customerRole in allCustomerRoles)
                {
                    //ensure that the current customer cannot add to "Administrators" system role if he's not an admin himself
                    if (customerRole.SystemName == SystemCustomerRoleNames.Registered ||
                        customerRole.SystemName == SystemCustomerRoleNames.Vendors)
                    {
                        customer.CustomerRoles.Add(customerRole);
                    }
                }

                //password
                if (!String.IsNullOrWhiteSpace(model.Password))
                {
                    var changePassRequest = new ChangePasswordRequest(model.Email, false, _customerSettings.DefaultPasswordFormat, model.Password);
                    var changePassResult  = _customerRegistrationService.ChangePassword(changePassRequest);
                    if (!changePassResult.Success)
                    {
                        foreach (var changePassError in changePassResult.Errors)
                        {
                            ErrorNotification(changePassError);
                        }
                    }
                }

                if (string.IsNullOrWhiteSpace(model.Address.Address1))
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress, model.Address.Address1);
                }
                if (string.IsNullOrWhiteSpace(model.Address.Address2))
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StreetAddress2, model.Address.Address2);
                }
                if (string.IsNullOrWhiteSpace(model.Address.ZipPostalCode))
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.ZipPostalCode, model.Address.ZipPostalCode);
                }
                if (string.IsNullOrWhiteSpace(model.Address.City))
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.City, model.Address.City);
                }
                if (model.Address.CountryId > 0)
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.CountryId, model.Address.CountryId);
                }
                if (model.Address.StateProvinceId > 0)
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.StateProvinceId, model.Address.StateProvinceId);
                }
                if (string.IsNullOrWhiteSpace(model.Address.PhoneNumber))
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Phone, model.Address.PhoneNumber);
                }
                if (string.IsNullOrWhiteSpace(model.Address.FaxNumber))
                {
                    _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.Fax, model.Address.FaxNumber);
                }

                _customerService.UpdateCustomer(customer);

                //activity log
                _customerActivityService.InsertActivity("AddNewVendor", _localizationService.GetResource("ActivityLog.AddNewVendor"), vendor.Id);

                //search engine name
                model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, model.SeName, 0);

                //address
                var address = model.Address.ToEntity();
                address.CreatedOnUtc = DateTime.UtcNow;
                //some validation
                if (address.CountryId == 0)
                {
                    address.CountryId = null;
                }
                if (address.StateProvinceId == 0)
                {
                    address.StateProvinceId = null;
                }
                _addressService.InsertAddress(address);
                vendor.AddressId = address.Id;
                _vendorService.UpdateVendor(vendor);

                //locales
                UpdateLocales(vendor, model);
                //update picture seo file name
                UpdatePictureSeoNames(vendor);



                SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabName();

                    return(RedirectToAction("Edit", new { id = vendor.Id }));
                }
                return(RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareVendorModel(model, null, true, true);
            return(View(model));
        }