Beispiel #1
0
        public virtual Picture UpdatePicture(int pictureId, byte[] pictureBinary, string mimeType, string seoFilename, bool isNew, bool validateBinary = true)
        {
            mimeType    = mimeType.EmptyNull().Truncate(20);
            seoFilename = seoFilename.Truncate(100);

            if (validateBinary)
            {
                pictureBinary = ValidatePicture(pictureBinary);
            }

            var picture = GetPictureById(pictureId);

            if (picture == null)
            {
                return(null);
            }

            //delete old thumbs if a picture has been changed
            if (seoFilename != picture.SeoFilename)
            {
                _imageCache.DeleteCachedImages(picture);
            }

            picture.PictureBinary = (this.StoreInDb ? pictureBinary : new byte[0]);
            picture.MimeType      = mimeType;
            picture.SeoFilename   = seoFilename;
            picture.IsNew         = isNew;
            picture.UpdatedOnUtc  = DateTime.UtcNow;

            _pictureRepository.Update(picture);

            if (!this.StoreInDb)
            {
                SavePictureInFile(picture.Id, pictureBinary, mimeType);
            }

            //event notification
            _eventPublisher.EntityUpdated(picture);

            return(picture);
        }
Beispiel #2
0
        /// <summary>
        /// 更新电子邮件账号
        ///
        /// </summary>
        /// <param name="emailAccount"></param>
        public void UpdateEmailAccount(EmailAccount emailAccount)
        {
            if (emailAccount == null)
            {
                throw new ArgumentNullException("emailAccount");
            }
            emailAccount.Email       = CommonHelper.EnsureNotNull(emailAccount.Email).Trim();
            emailAccount.DisplayName = CommonHelper.EnsureNotNull(emailAccount.DisplayName).Trim();
            emailAccount.Host        = CommonHelper.EnsureNotNull(emailAccount.Host).Trim();
            emailAccount.UserName    = CommonHelper.EnsureNotNull(emailAccount.UserName);
            emailAccount.Password    = CommonHelper.EnsureNotNull(emailAccount.Password).Trim();


            emailAccount.Email       = CommonHelper.EnsureMaximumLength(emailAccount.Email, 255);
            emailAccount.DisplayName = CommonHelper.EnsureMaximumLength(emailAccount.DisplayName, 255);
            emailAccount.Host        = CommonHelper.EnsureMaximumLength(emailAccount.Host, 255);
            emailAccount.UserName    = CommonHelper.EnsureMaximumLength(emailAccount.UserName, 255);
            emailAccount.Password    = CommonHelper.EnsureMaximumLength(emailAccount.Password, 255);
            _emailAccountRepository.Update(emailAccount);
            _eventPublisher.EntityUpdated(emailAccount);
        }
Beispiel #3
0
        /// <summary>
        /// Updates a language
        /// </summary>
        /// <param name="language">Language</param>
        public virtual void UpdateLanguage(Language language)
        {
            if (language == null)
            {
                throw new ArgumentNullException(nameof(language));
            }

            if (language is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }

            //update language
            _languageRepository.Update(language);

            //cache
            _cacheManager.RemoveByPattern(NopLocalizationDefaults.LanguagesPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(language);
        }
        /// <summary>
        /// Updates a newsletter subscription
        /// </summary>
        /// <param name="newsLetterSubscription">NewsLetter subscription</param>
        public virtual void UpdateNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription)
        {
            if (newsLetterSubscription == null)
            {
                throw new ArgumentNullException("newsLetterSubscription");
            }

            newsLetterSubscription.Email = CommonHelper.EnsureNotNull(newsLetterSubscription.Email);
            newsLetterSubscription.Email = newsLetterSubscription.Email.Trim();
            newsLetterSubscription.Email = CommonHelper.EnsureMaximumLength(newsLetterSubscription.Email, 255);

            if (!CommonHelper.IsValidEmail(newsLetterSubscription.Email))
            {
                throw new NopException("Email is not valid.");
            }

            _newsLetterSubscriptionRepository.Update(newsLetterSubscription);

            //event notification
            _eventPublisher.EntityUpdated(newsLetterSubscription);
        }
        /// <summary>
        /// Updates a state/province
        /// </summary>
        /// <param name="stateProvince">State/province</param>
        public virtual void UpdateStateProvince(StateProvince stateProvince)
        {
            if (stateProvince == null)
            {
                throw new ArgumentNullException("stateProvince");
            }

            _stateProvinceRepository.Update(stateProvince);
            if (stateProvince.Published)
            {
                InsertOrUpdateDiaDiem(stateProvince.Id, ENLoaiDiaDiem.Tinh, stateProvince.Name);
            }
            else
            {
                DeleteDiaDiem(stateProvince.Id, ENLoaiDiaDiem.Tinh);
            }
            _cacheManager.RemoveByPattern(STATEPROVINCES_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(stateProvince);
        }
Beispiel #6
0
        public virtual void UpdateCompany(Company company)
        {
            if (company == null)
            {
                throw new ArgumentNullException(nameof(company));
            }

            if (company is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }

            _companyRepository.Update(company);

            //cache
            _cacheManager.RemoveByPrefix(NopCatalogDefaults.CompaniesPrefixCacheKey);
            _staticCacheManager.RemoveByPrefix(NopCatalogDefaults.CompaniesPrefixCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(company);
        }
Beispiel #7
0
        /// <summary>
        /// Updates the attribute
        /// </summary>
        /// <param name="attribute">Attribute</param>
        public virtual void UpdateAttribute(GenericAttribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            _genericAttributeRepository.Update(attribute);

            //cache
            _cacheManager.RemoveByPattern(GENERICATTRIBUTE_PATTERN_KEY);

            //event notifications
            _eventPublisher.EntityUpdated(attribute);

            if (attribute.KeyGroup.IsCaseInsensitiveEqual("Order") && attribute.EntityId != 0)
            {
                var order = _orderRepository.GetById(attribute.EntityId);
                _eventPublisher.PublishOrderUpdated(order);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Updates the address
        /// </summary>
        /// <param name="address">Address</param>
        public virtual void UpdateAddressSettings(Address address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

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

            _addressRepository.Update(address);

            //cache
            _cacheManager.RemoveByPattern(ADDRESSES_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(address);
        }
Beispiel #9
0
        public void UpdateForumGroup(ForumGroup forumGroup)
        {
            if (forumGroup == null)
            {
                throw new ArgumentNullException("forumGroup");
            }

            _forumGroupRepository.Update(forumGroup);

            //cache
            _cacheManager.RemoveByPattern(FORUMGROUP_PATTERN_KEY);
            _cacheManager.RemoveByPattern(FORUM_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(forumGroup);
        }
Beispiel #10
0
        /// <summary>
        /// Updates a newsletter subscription
        /// </summary>
        /// <param name="newsLetterSubscription">NewsLetter subscription</param>
        /// <param name="publishSubscriptionEvents">if set to <c>true</c> [publish subscription events].</param>
        public virtual void UpdateNewsLetterSubscription(NewsLetterSubscription newsLetterSubscription, bool publishSubscriptionEvents = true)
        {
            if (newsLetterSubscription == null)
            {
                throw new ArgumentNullException(nameof(newsLetterSubscription));
            }

            //Handle e-mail
            newsLetterSubscription.Email = CommonHelper.EnsureSubscriberEmailOrThrow(newsLetterSubscription.Email);

            //Get original subscription record
            var originalSubscription = _context.LoadOriginalCopy(newsLetterSubscription);

            //Persist
            _subscriptionRepository.Update(newsLetterSubscription);

            //Publish the subscription event
            if ((originalSubscription.Active == false && newsLetterSubscription.Active) ||
                (newsLetterSubscription.Active && originalSubscription.Email != newsLetterSubscription.Email))
            {
                //If the previous entry was false, but this one is true, publish a subscribe.
                PublishSubscriptionEvent(newsLetterSubscription, true, publishSubscriptionEvents);
            }

            if (originalSubscription.Active && newsLetterSubscription.Active &&
                originalSubscription.Email != newsLetterSubscription.Email)
            {
                //If the two emails are different publish an unsubscribe.
                PublishSubscriptionEvent(originalSubscription, false, publishSubscriptionEvents);
            }

            if (originalSubscription.Active && !newsLetterSubscription.Active)
            {
                //If the previous entry was true, but this one is false
                PublishSubscriptionEvent(originalSubscription, false, publishSubscriptionEvents);
            }

            //Publish event
            _eventPublisher.EntityUpdated(newsLetterSubscription);
        }
Beispiel #11
0
        public virtual async Task UpdateAsync(TblUsers record, string password)
        {
            if (await _dbContext.Users.AnyAsync(p => p.Email.Trim() == record.Email.Trim() && p.Id != record.Id))
            {
                throw new Exception($"The \"{record.Email}\" email address already exists.");
            }

            var oldRecord = await UserManager.FindByIdAsync(record.Id);

            if (oldRecord != null)
            {
                record.UserName = record.Email;
                if (string.IsNullOrWhiteSpace(record.Avatar))
                {
                    record.Avatar = oldRecord.Avatar;
                }

                if (string.IsNullOrEmpty(password))
                {
                    record.PasswordHash = oldRecord.PasswordHash;
                }
                else
                {
                    var passwordValidatorResult = await UserManager.PasswordValidator.ValidateAsync(password);

                    if (!passwordValidatorResult.Succeeded)
                    {
                        throw new Exception(passwordValidatorResult.Errors.StringJoin(Environment.NewLine));
                    }
                    record.PasswordHash = HashPassword(password);
                }

                record.SecurityStamp = oldRecord.SecurityStamp;

                _dbContext.Users.AddOrUpdate(record);
                await _dbContext.SaveChangesAsync();

                _eventPublisher.EntityUpdated(record, oldRecord);
            }
        }
Beispiel #12
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public PublicResult UpdateCategory(UpdateCategoryDto dto)
        {
            Category category = null;

            using (var client = DbFactory.CreateClient())
            {
                category = client.Queryable <Category>().InSingle(dto.Id);
                if (category == null)
                {
                    return(Error("找不到该条信息"));
                }
                category.Name        = dto.Name;
                category.Alias       = dto.Alias;
                category.Description = dto.Description;
                category.ParentId    = dto.ParentId;
                client.Updateable(category).ExecuteCommand();
            }
            UpdatePathByCategoryId(category.Id);
            _distributedCache.Remove(CACHE_CATEGORY_ALL_KEY);
            _eventPublisher.EntityUpdated(category);
            return(Ok());
        }
        /// <summary>
        /// Updates the educationLevel
        /// </summary>
        /// <param name="educationLevel">EducationLevel</param>
        public virtual void UpdateEducationLevel(EducationLevel educationLevel)
        {
            if (educationLevel == null)
            {
                throw new ArgumentNullException(nameof(educationLevel));
            }

            if (educationLevel is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _educationLevelRepository.Update(educationLevel);

            //cache
            _cacheManager.RemoveByPattern(ResearchEducationLevelDefaults.EducationLevelsPatternCacheKey);
            //_staticCacheManager.RemoveByPattern(ResearchEducationLevelDefaults.EducationLevelsPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(educationLevel);
        }
Beispiel #14
0
        /// <inheritdoc />
        ///  <summary>
        ///  </summary>
        ///  <param name="viewModel"></param>
        ///  <returns></returns>
        public async Task EditByViewModelAsync(RoleEditViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var role = await _roleRepository.FirstOrDefaultAsync(model => model.Id == viewModel.Id);

            _mapper.Map(viewModel, role);

            var permissionIds = viewModel.Permissions.Split(',');

            role.RolePermissions = new HashSet <RolePermission>();
            permissionIds.ForEach(permissionId => role.RolePermissions.Add(new RolePermission {
                PermissionId = permissionId.ToGuidOrDefault()
            }));

            await _unitOfWork.SaveAllChangesAsync();

            _eventPublisher.EntityUpdated(role);
        }
        /// <summary>
        /// Updates the faculty
        /// </summary>
        /// <param name="faculty">Faculty</param>
        public virtual void UpdateFaculty(Faculty faculty)
        {
            if (faculty == null)
            {
                throw new ArgumentNullException(nameof(faculty));
            }

            if (faculty is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _facultyRepository.Update(faculty);

            //cache
            _cacheManager.RemoveByPattern(ResearchFacultyDefaults.FacultiesPatternCacheKey);
            //_staticCacheManager.RemoveByPattern(ResearchFacultyDefaults.FacultiesPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(faculty);
        }
Beispiel #16
0
        /// <summary>
        /// Updates the address
        /// </summary>
        /// <param name="address">Address</param>
        public virtual void UpdateAddress(Address address)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (address is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _addressRepository.Update(address);

            //cache
            _cacheManager.RemoveByPattern(ResearchAddressDefaults.AddressesPatternCacheKey);
            //_staticCacheManager.RemoveByPattern(ResearchAddressDefaults.AddressesPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(address);
        }
Beispiel #17
0
        /// <summary>
        /// Updates the institute
        /// </summary>
        /// <param name="institute">Institute</param>
        public virtual void UpdateInstitute(Institute institute)
        {
            if (institute == null)
            {
                throw new ArgumentNullException(nameof(institute));
            }

            if (institute is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _instituteRepository.Update(institute);

            //cache
            _cacheManager.RemoveByPattern(ResearchInstituteDefaults.InstitutesPatternCacheKey);
            //_staticCacheManager.RemoveByPattern(ResearchInstituteDefaults.InstitutesPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(institute);
        }
        /// <summary>
        /// Updates the professor
        /// </summary>
        /// <param name="professor">Professor</param>
        public virtual void UpdateProfessor(Professor professor)
        {
            if (professor == null)
            {
                throw new ArgumentNullException(nameof(professor));
            }

            if (professor is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _professorRepository.Update(professor);

            //cache
            _cacheManager.RemoveByPattern(ResearchProfessorDefaults.ProfessorsPatternCacheKey);
            //_staticCacheManager.RemoveByPattern(ResearchProfessorDefaults.ProfessorsPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(professor);
        }
        /// <summary>
        /// Updates the strategyGroup
        /// </summary>
        /// <param name="strategyGroup">StrategyGroup</param>
        public virtual void UpdateStrategyGroup(StrategyGroup strategyGroup)
        {
            if (strategyGroup == null)
            {
                throw new ArgumentNullException(nameof(strategyGroup));
            }

            if (strategyGroup is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _strategyGroupRepository.Update(strategyGroup);

            //cache
            _cacheManager.RemoveByPattern(ResearchStrategyGroupDefaults.StrategyGroupsPatternCacheKey);
            //_staticCacheManager.RemoveByPattern(ResearchStrategyGroupDefaults.StrategyGroupsPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(strategyGroup);
        }
Beispiel #20
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ServResult UpdateCategory(ServRequest <UpdateCategoryDto> request)
        {
            Category category = null;

            using (var client = DbFactory.GetClient())
            {
                category = client.Queryable <Category>().InSingle(request.Data.Id);
                if (category == null)
                {
                    return(Error("找不到该条信息"));
                }
                category.Name        = request.Data.Name;
                category.Alias       = request.Data.Alias;
                category.Description = request.Data.Description;
                category.ParentId    = request.Data.ParentId;
                client.Updateable(category).ExecuteCommand();
            }
            UpdatePathByCategoryId(category.Id);
            _distributedCache.Remove(CACHE_CATEGORY_ALL_KEY);
            _eventPublisher.EntityUpdated(category);
            return(Ok());
        }
Beispiel #21
0
        /// <summary>
        /// Updates the picture
        /// </summary>
        /// <param name="pictureId">The picture identifier</param>
        /// <param name="pictureBinary">The picture binary</param>
        /// <param name="mimeType">The picture MIME type</param>
        /// <param name="seoFilename">The SEO filename</param>
        /// <param name="isNew">A value indicating whether the picture is new</param>
        /// <returns>Picture</returns>
        public virtual Picture UpdatePicture(int pictureId, byte[] pictureBinary, string mimeType, string seoFilename, bool isNew)
        {
            mimeType = CommonHelper.EnsureNotNull(mimeType);
            mimeType = CommonHelper.EnsureMaximumLength(mimeType, 20);

            seoFilename = CommonHelper.EnsureMaximumLength(seoFilename, 100);

            ValidatePicture(pictureBinary, mimeType);

            var picture = GetPictureById(pictureId);

            if (picture == null)
            {
                return(null);
            }

            //delete old thumbs if a picture has been changed
            if (seoFilename != picture.SeoFilename)
            {
                DeletePictureThumbs(picture);
            }

            picture.PictureBinary = (this.StoreInDb ? pictureBinary : new byte[0]);
            picture.MimeType      = mimeType;
            picture.SeoFilename   = seoFilename;
            picture.IsNew         = isNew;

            _pictureRepository.Update(picture);

            if (!this.StoreInDb)
            {
                SavePictureInFile(picture.Id, pictureBinary, mimeType);
            }

            //event notification
            _eventPublisher.EntityUpdated(picture);

            return(picture);
        }
        /// <summary>
        /// Updates the fiscalSchedule
        /// </summary>
        /// <param name="fiscalSchedule">FiscalSchedule</param>
        public virtual void UpdateFiscalSchedule(FiscalSchedule fiscalSchedule)
        {
            if (fiscalSchedule == null)
            {
                throw new ArgumentNullException(nameof(fiscalSchedule));
            }

            if (fiscalSchedule is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _fiscalScheduleRepository.Update(fiscalSchedule);

            //cache
            _cacheManager.RemoveByPattern(ResearchFiscalScheduleDefaults.FiscalSchedulesPatternCacheKey);
            // _staticCacheManager.RemoveByPattern(ResearchFiscalScheduleDefaults.FiscalSchedulesPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(fiscalSchedule);
        }
        /// <summary>
        /// Updates the address
        /// </summary>
        /// <param name="address">Address</param>
        public virtual void UpdateAddress(Address address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

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

            _addressRepository.Update(address);

            //event notification
            _eventPublisher.EntityUpdated(address);
        }
        /// <summary>
        /// Updates the academicRank
        /// </summary>
        /// <param name="academicRank">AcademicRank</param>
        public virtual void UpdateAcademicRank(AcademicRank academicRank)
        {
            if (academicRank == null)
            {
                throw new ArgumentNullException(nameof(academicRank));
            }

            if (academicRank is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }


            _academicRankRepository.Update(academicRank);

            //cache
            _cacheManager.RemoveByPattern(ResearchAcademicRankDefaults.AcademicRanksPatternCacheKey);
            //_staticCacheManager.RemoveByPattern(ResearchAcademicRankDefaults.AcademicRanksPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(academicRank);
        }
        public Picture UpdatePictureBase(int pictureId, byte[] pictureBinary, string mimeType,
                                         string seoFilename, string altAttribute = null, string titleAttribute = null,
                                         bool isNew = true, bool validateBinary = true)
        {
            mimeType = CommonHelper.EnsureNotNull(mimeType);
            mimeType = CommonHelper.EnsureMaximumLength(mimeType, 20);

            seoFilename = CommonHelper.EnsureMaximumLength(seoFilename, 100);



            var picture = GetPictureById(pictureId);

            if (picture == null)
            {
                return(null);
            }

            //delete old thumbs if a picture has been changed
            if (seoFilename != picture.SeoFilename)
            {
                DeletePictureThumbs(picture);
            }

            picture.PictureBinary  = pictureBinary;
            picture.MimeType       = mimeType;
            picture.SeoFilename    = seoFilename;
            picture.AltAttribute   = altAttribute;
            picture.TitleAttribute = titleAttribute;
            picture.IsNew          = isNew;

            _pictureRepository.Update(picture);

            //event notification
            _eventPublisher.EntityUpdated(picture);

            return(picture);
        }
Beispiel #26
0
        public Picture UpdatePicture(int pictureId, byte[] pictureBinary, string mimeType, string seoFilename,
                                     string altAttribute = null, string titleAttribute = null, bool validateBinary = true)
        {
            mimeType = CommonHelper.EnsureNotNull(mimeType);
            mimeType = CommonHelper.EnsureMaximumLength(mimeType, 20);

            seoFilename = CommonHelper.EnsureMaximumLength(seoFilename, 100);

            if (validateBinary)
            {
                pictureBinary = ValidatePicture(pictureBinary, mimeType);
            }

            var picture = GetPictureById(pictureId);

            if (picture == null)
            {
                return(null);
            }

            if (seoFilename != picture.SeoFilename)
            {
                DeletePictureThumbs(picture);
            }

            picture.MimeType       = mimeType;
            picture.SeoFilename    = seoFilename;
            picture.AltAttribute   = altAttribute;
            picture.TitleAttribute = titleAttribute;

            _pictureRepository.Update(picture);

            SavePictureInFile(picture.Id, pictureBinary, mimeType);

            _eventPublisher.EntityUpdated(picture);

            return(picture);
        }
Beispiel #27
0
        /// <summary>
        /// Updates the product tag
        /// </summary>
        /// <param name="productTag">Product tag</param>
        public virtual void UpdateProductTag(ProductTag productTag)
        {
            if (productTag == null)
            {
                throw new ArgumentNullException("productTag");
            }

            _productTagRepository.Update(productTag);

            var builder = Builders <Product> .Filter;
            var filter  = builder.ElemMatch(x => x.ProductTags, y => y.Id == productTag.Id);
            var update  = Builders <Product> .Update
                          .Set(x => x.ProductTags.ElementAt(-1).Name, productTag.Name)
                          .Set(x => x.ProductTags.ElementAt(-1).Locales, productTag.Locales);

            var result = _productRepository.Collection.UpdateManyAsync(filter, update).Result;

            //cache
            _cacheManager.RemoveByPattern(PRODUCTTAG_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(productTag);
        }
Beispiel #28
0
        public async Task <Picture> UpdatePicture(int pictureId, byte[] pictureBinary, string mimeType,
                                                  string altAttribute = null, string titleAttribute = null, bool isNew = true, bool validateBinary = true)
        {
            mimeType = CommonHelper.EnsureNotNull(mimeType);
            mimeType = CommonHelper.EnsureMaximumLength(mimeType, 20);

            if (validateBinary)
            {
                pictureBinary = ValidatePicture(pictureBinary, mimeType);
            }

            var picture = await GetPictureById(pictureId);

            if (picture == null)
            {
                return(null);
            }

            picture.MimeType       = mimeType;
            picture.AltAttribute   = altAttribute;
            picture.TitleAttribute = titleAttribute;
            picture.IsNew          = isNew;

            await _pictureRepository.UpdateAsync(picture);

            UpdatePictureBinary(picture, StoreInDb ? pictureBinary : new byte[0]);

            if (!StoreInDb)
            {
                SavePictureInFile(picture.Id, pictureBinary, mimeType);
            }

            _eventPublisher.EntityUpdated(picture);

            return(picture);
        }
        public virtual void UpdateCategorySpecificationAtrribute(CategorySpecificationAtrribute categorySpecificationAtrribute)
        {
            if (categorySpecificationAtrribute == null)
            {
                throw new ArgumentNullException("categorySpecificationAtrribute");
            }

            //validate category hierarchy
            var CategorySpecificationAtrribute = GetCategorySpecificationAtrributeBySid(categorySpecificationAtrribute.SpecificationAttributeId);

            if (CategorySpecificationAtrribute != null)
            {
                CategorySpecificationAtrribute.AllowFiltering           = categorySpecificationAtrribute.AllowFiltering;
                CategorySpecificationAtrribute.Deleted                  = categorySpecificationAtrribute.Deleted;
                CategorySpecificationAtrribute.CategoryId               = categorySpecificationAtrribute.CategoryId;
                CategorySpecificationAtrribute.SpecificationAttributeId = categorySpecificationAtrribute.SpecificationAttributeId;
                _categorySpecificationAtrributeRepository.Update(CategorySpecificationAtrribute);
            }
            //cache
            _cacheManager.RemoveByPattern(CATEGORYSPECIFICATIONATTRIBUTE_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(categorySpecificationAtrribute);
        }
Beispiel #30
0
        /// <summary>
        /// Updates the category
        /// </summary>
        /// <param name="category">Category</param>
        public virtual void UpdateCategory(Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            if (category is IEntityForCaching)
            {
                throw new ArgumentException("Cacheable entities are not supported by Entity Framework");
            }

            //validate category hierarchy
            var parentCategory = GetCategoryById(category.ParentCategoryId);

            while (parentCategory != null)
            {
                if (category.Id == parentCategory.Id)
                {
                    category.ParentCategoryId = 0;
                    break;
                }

                parentCategory = GetCategoryById(parentCategory.ParentCategoryId);
            }

            _categoryRepository.Update(category);

            //cache
            _cacheManager.RemoveByPattern(GSCatalogDefaults.CategoriesPatternCacheKey);
            _staticCacheManager.RemoveByPattern(GSCatalogDefaults.CategoriesPatternCacheKey);
            _cacheManager.RemoveByPattern(GSCatalogDefaults.ProductCategoriesPatternCacheKey);

            //event notification
            _eventPublisher.EntityUpdated(category);
        }