public void AddFeatureDetailAvailability(FeatureDetailDto featureDetailDto, long adminId) { var user = _userService.Find(adminId); if (user == null) { throw new NotFoundException(ErrorCodes.UserNotFound); } ValidateFeatureDetail(featureDetailDto, adminId); var featureDetail = _featureDetailService.Find(featureDetailDto.FeatureDetailId); var available = Mapper.Map <Available>(featureDetailDto.Availables.FirstOrDefault()); if (featureDetail != null) { featureDetail.ModifiedBy = adminId; featureDetail.ModifyTime = DateTime.Now; _availableService.Insert(available); } else { featureDetail = Mapper.Map <FeatureDetail>(featureDetailDto); featureDetail.CreationBy = adminId; featureDetail.CreateTime = DateTime.Now; _featureDetailTranslationService.InsertRange(featureDetail.FeatureDetailTranslations); _featureDetailService.Insert(featureDetail); } SaveChanges(); }
public void UpdateFeatureDetailAvailability(FeatureDetailDto featureDetailDto, long adminId) { var user = _userService.Find(adminId); if (user == null) { throw new NotFoundException(ErrorCodes.UserNotFound); } var featureDetail = _featureDetailService.Find(featureDetailDto.FeatureDetailId); ValidateFeatureDetail(featureDetailDto, adminId); //var featureDetail = Mapper.Map<FeatureDetail>(featureDetailDto); featureDetail.ModifiedBy = adminId; featureDetail.ModifyTime = DateTime.Now; foreach (var availableDto in featureDetailDto.Availables) { var available = featureDetail.Availables.FirstOrDefault(x => x.AvailableId == availableDto.AvailableId); if (available == null) { featureDetail.Availables.Add(new Available { Day = availableDto.Day, From = availableDto.From, To = availableDto.To, Max = availableDto.Max }); } else { available.Day = availableDto.Day; available.From = availableDto.From; available.To = availableDto.To; available.Max = availableDto.Max; } } _featureDetailService.Update(featureDetail); SaveChanges(); }
private void ValidateFeatureDetail(FeatureDetailDto featureDetail, long userId) { foreach (var description in featureDetail.DescriptionDictionary) { if (string.IsNullOrEmpty(description.Value)) { throw new ValidationException(ErrorCodes.EmptyFeatureName); } if (description.Value.Length > 300) { throw new ValidationException(ErrorCodes.FeatureNameExceedLength); } if (_featureDetailTranslationService.CheckFeatureDetailDescriptionExist(description.Value, description.Key, featureDetail.FeatureDetailId, userId) ) { throw new ValidationException(ErrorCodes.FeatureNameAlreadyExist); } } }
public void AddFeatureDetail(FeatureDetailDto featureDetailDto, long adminId, string path) { var user = _userService.Find(adminId); if (user == null) { throw new NotFoundException(ErrorCodes.UserNotFound); } ValidateFeatureDetail(featureDetailDto, adminId); var featureDetail = Mapper.Map <FeatureDetail>(featureDetailDto); featureDetail.CreationBy = adminId; featureDetail.CreateTime = DateTime.Now; //foreach (var featureName in featureDetailDto.DescriptionDictionary) //{ // featureDetail.FeatureTranslations.Add(new FeatureTranslation // { // FeatureName = featureName.Value, // Language = featureName.Key.ToLower() // }); //} //featureDetail.FeatureDetails.ForEach(x => _featureDetailTranslationService.InsertRange(x.FeatureDetailTranslations)); _availableService.InsertRange(featureDetail.Availables); _featureDetailTranslationService.InsertRange(featureDetail.FeatureDetailTranslations); _featureDetailService.Insert(featureDetail); SaveChanges(); if (featureDetailDto.IsImageChange) { var featureControl = _featureControlService.Find(featureDetail.FeatureControlId); _manageStorage.UploadImage(path + "\\" + "Feature-" + featureControl.FeatureId + "\\Detail-" + featureDetail.FeatureDetailId, featureDetailDto.Image, featureDetail.FeatureDetailId.ToString()); } }
public void UpdateFeatureDetail(FeatureDetailDto featureDetailDto, long adminId, string path) { var user = _userService.Find(adminId); if (user == null) { throw new NotFoundException(ErrorCodes.UserNotFound); } var featureDetail = _featureDetailService.Find(featureDetailDto.FeatureDetailId); ValidateFeatureDetail(featureDetailDto, adminId); //var featureDetail = Mapper.Map<FeatureDetail>(featureDetailDto); featureDetail.ModifiedBy = adminId; featureDetail.ModifyTime = DateTime.Now; featureDetail.Link = featureDetailDto.Link; featureDetail.IsFree = featureDetailDto.IsFree; featureDetail.Price = featureDetailDto.Price; //featureDetail.Availables = Mapper.Map<List<Available>>(featureDetailDto.Availables); foreach (var featureName in featureDetailDto.DescriptionDictionary) { var featureDetailTranslation = featureDetail.FeatureDetailTranslations.FirstOrDefault(x => x.Language.ToLower() == featureName.Key.ToLower()); if (featureDetailTranslation == null) { featureDetail.FeatureDetailTranslations.Add(new FeatureDetailTranslation { Language = featureName.Key.ToLower(), Description = featureName.Value, }); } else { featureDetailTranslation.Description = featureName.Value; } } featureDetail.Availables.ForEach(x => x.IsDeleted = true); foreach (var availableDto in featureDetailDto.Availables) { var available = featureDetail.Availables.FirstOrDefault(x => x.AvailableId == availableDto.AvailableId && availableDto.AvailableId > 0); if (available == null) { available = new Available { From = availableDto.From, To = availableDto.To, Max = availableDto.Max, Day = availableDto.Day, IsDeleted = false }; featureDetail.Availables.Add(available); //_availableService.Insert(available); } else { available.From = availableDto.From; available.To = availableDto.To; available.Max = availableDto.Max; available.IsDeleted = false; //_availableService.Update(available); } } //_featureDetailTranslationService.InsertRange(featureDetail.FeatureDetailTranslations); //_availableService.InsertOrUpdateRange(featureDetail.Availables); _featureDetailService.Update(featureDetail); SaveChanges(); if (featureDetailDto.IsImageChange) { var featureControl = _featureControlService.Find(featureDetail.FeatureControlId); _manageStorage.UploadImage(path + "\\" + "Feature-" + featureControl.FeatureId + "\\Detail-" + featureDetail.FeatureDetailId, featureDetailDto.Image, featureDetail.FeatureDetailId.ToString()); } }