Exemple #1
0
        public virtual ActionResult Create(PublisherModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePublishers))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var publisher = model.ToEntity();
                publisher.CreatedOnUtc = DateTime.UtcNow;
                publisher.UpdatedOnUtc = DateTime.UtcNow;
                _publisherService.InsertPublisher(publisher);
                //search engine name
                model.SeName = publisher.ValidateSeName(model.SeName, publisher.Name, true);
                _urlRecordService.SaveSlug(publisher, model.SeName, 0);
                //locales
                UpdateLocales(publisher, model);

                _publisherService.UpdatePublisher(publisher);
                //update picture seo file name
                UpdatePictureSeoNames(publisher);
                //ACL (customer roles)
                SavePublisherAcl(publisher, model);
                //Stores
                SaveStoreMappings(publisher, model);

                //activity log
                _customerActivityService.InsertActivity("AddNewPublisher", _localizationService.GetResource("ActivityLog.AddNewPublisher"), publisher.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Publishers.Added"));

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

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

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

            //ACL
            PrepareAclModel(model, null, true);
            //Stores
            PrepareStoresMappingModel(model, null, true);

            return(View(model));
        }
Exemple #2
0
        public virtual ActionResult Edit(PublisherModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePublishers))
            {
                return(AccessDeniedView());
            }

            var publisher = _publisherService.GetPublisherById(model.Id);

            if (publisher == null || publisher.Deleted)
            {
                //No publisher found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                int prevPictureId = publisher.PictureId;
                publisher = model.ToEntity(publisher);
                publisher.UpdatedOnUtc = DateTime.UtcNow;
                _publisherService.UpdatePublisher(publisher);
                //search engine name
                model.SeName = publisher.ValidateSeName(model.SeName, publisher.Name, true);
                _urlRecordService.SaveSlug(publisher, model.SeName, 0);
                //locales
                UpdateLocales(publisher, model);

                _publisherService.UpdatePublisher(publisher);
                //delete an old picture (if deleted or updated)
                if (prevPictureId > 0 && prevPictureId != publisher.PictureId)
                {
                    var prevPicture = _pictureService.GetPictureById(prevPictureId);
                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }
                //update picture seo file name
                UpdatePictureSeoNames(publisher);
                //ACL
                SavePublisherAcl(publisher, model);
                //Stores
                SaveStoreMappings(publisher, model);

                //activity log
                _customerActivityService.InsertActivity("EditPublisher", _localizationService.GetResource("ActivityLog.EditPublisher"), publisher.Name);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Publishers.Updated"));

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

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


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

            //ACL
            PrepareAclModel(model, publisher, true);
            //Stores
            PrepareStoresMappingModel(model, publisher, true);

            return(View(model));
        }