public ExceptionForm(Exception exception) : this() { CheckHelper.ArgumentNotNull(exception, "exception"); Exception = exception; }
public DTO.SubCategory CreateSubCategory(DataAccess.SubCategory subCategory, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(subCategory, "subCategory"); CheckHelper.ArgumentWithinCondition(!subCategory.IsNew(), "!subCategory.IsNew()"); return (_dtoCache.Get( subCategory, sc => { var result = new DTO.SubCategory { Id = sc.Id, Name = sc.Name, Active = sc.Active }; CopyTrackableFields(result, sc); return result; }, (scDto, sc) => scDto.Category = CreateCategory(sc.Category, includeOnlyActive))); }
public void UpdateBrand(DTO.Brand updatedBrand) { CheckHelper.ArgumentNotNull(updatedBrand, "updatedBrand"); CheckHelper.ArgumentWithinCondition(!updatedBrand.IsNew(), "Brand is new."); Container.Get <IValidateService>().CheckIsValid(updatedBrand); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can change brand."); var persistentService = Container.Get <IPersistentService>(); var brand = persistentService.GetEntityById <DataAccess.Brand>(updatedBrand.Id); CheckHelper.NotNull(brand, "Brand does not exist."); if (brand.Name != updatedBrand.Name) { var doesAnotherBrandWithTheSameNameExist = persistentService .GetEntitySet <DataAccess.Brand>() .Any(b => b.Name == updatedBrand.Name); if (doesAnotherBrandWithTheSameNameExist) { throw new BrandServiceException("Бренд с заданным названием уже существует."); } } brand.Name = updatedBrand.Name; brand.Active = updatedBrand.Active; brand.UpdateTrackFields(Container); persistentService.SaveChanges(); }
public DTO.ProductSize CreateProductSize(DataAccess.ProductSize productSize, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(productSize, "productSize"); CheckHelper.ArgumentWithinCondition(!productSize.IsNew(), "!productSize.IsNew()"); return (_dtoCache.Get( productSize, ps => { var result = new DTO.ProductSize { Id = ps.Id, Price = ps.Price, Active = ps.Active }; CopyTrackableFields(result, ps); return result; }, (psDto, ps) => { psDto.Size = CreateSize(ps.Size, includeOnlyActive); psDto.Product = CreateProduct(ps.Product, includeOnlyActive); })); }
public DTO.DistributorTransfer CreateDistributorTransfer(DataAccess.DistributorTransfer distributorTransfer, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(distributorTransfer, "distributorTransfer"); CheckHelper.ArgumentWithinCondition(!distributorTransfer.IsNew(), "!distributorTransfer.IsNew()"); return (_dtoCache.Get( distributorTransfer, dt => { var result = new DTO.DistributorTransfer { Id = dt.Id, Amount = dt.Amount, Date = dt.Date, Active = dt.Active, RublesPerDollar = dt.RublesPerDollar }; CopyTrackableFields(result, dt); return result; })); }
private void UpdateDistributor(DataAccess.Parcel parcel, DTO.User distributor) { CheckHelper.ArgumentNotNull(parcel, "parcel"); if (distributor != null) { var distributorId = distributor.Id; CheckHelper.WithinCondition(distributorId > 0, "Distributor is new."); var persistentService = Container.Get <IPersistentService>(); var user = persistentService.GetEntityById <User>(distributorId); CheckHelper.NotNull(user, "Distributor user does not exist."); CheckHelper.WithinCondition( user.UserRoles.Any(r => r.Role.Name == DTO.Role.DISTRIBUTOR_ROLE_NAME && r.Active), "User is not distributor."); parcel.DistributorId = user.Id; parcel.Distributor = user; } else { parcel.DistributorId = null; parcel.Distributor = null; } }
public DTO.User CreateUser(DataAccess.User user, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(user, "user"); CheckHelper.ArgumentWithinCondition(!user.IsNew(), "!user.IsNew()"); return (_dtoCache.Get( user, u => { var result = new DTO.User { Id = u.Id, Login = user.Login, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Active = u.Active }; CopyTrackableFields(result, u); return result; }, (uDto, u) => uDto.Roles = u.UserRoles .Where(ur => ur.Active || !includeOnlyActive) .Select(ur => ur.Role) .OrderBy(r => r.Name) .Select(r => CreateRole(r, includeOnlyActive)) .ToArray())); }
public DTO.ProductSize[] GetProductSizes(DTO.Product product, string filter) { CheckHelper.ArgumentNotNull(product, "product"); CheckHelper.ArgumentWithinCondition(!product.IsNew(), "!product.IsNew()"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can get all product sizes."); var query = Container .Get <IPersistentService>() .GetEntitySet <DataAccess.ProductSize>() .Where(ps => ps.ProductId == product.Id) .AsQueryable(); if (!string.IsNullOrWhiteSpace(filter)) { query = query.Where(ps => ps.Size.Name.Contains(filter)); } var dtoService = Container.Get <IDtoService>(); return (query .OrderBy(ps => ps.Size.Name) .ToArray() .Select(ps => dtoService.CreateProductSize(ps, false)) .ToArray()); }
public void NotifyUserCreated(User createdUser, string password) { CheckHelper.ArgumentNotNull(createdUser, "createdUser"); CheckHelper.ArgumentWithinCondition(!createdUser.IsNew(), "!createdUser.IsNew()"); Container.Get <IValidateService>().CheckIsValid(createdUser); CheckHelper.ArgumentNotNullAndNotWhiteSpace(password, "password"); CheckHelper.ArgumentWithinCondition(StringValidator.ValidatePassword(password), "password"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserAdministrator, "Current user is not administrator."); var install = Container.Get <IHttpService>().GetAbsoluteURLFromRelativeURL("Install/UsClothesSetup.exe"); var userFullName = createdUser.ToString(); var body = GetEmailBody("UserCreatedEmailTemplate", new Dictionary <string, string> { { "@user", userFullName }, { "@login", createdUser.Login }, { "@password", password }, { "@install", install } }); SendEmailMessage(createdUser.Email, userFullName, "Регистрация в системе US Clothes", body); }
public void UpdateDistributorTransfer(DTO.DistributorTransfer updatedDistributorTransfer) { CheckHelper.ArgumentNotNull(updatedDistributorTransfer, "updatedDistributorTransfer"); CheckHelper.ArgumentWithinCondition(!updatedDistributorTransfer.IsNew(), "Distributor Transfer is new."); Container.Get <IValidateService>().CheckIsValid(updatedDistributorTransfer); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserDistributor, "Only distributor can change distributor transfer."); var persistentService = Container.Get <IPersistentService>(); var distributorTransfer = persistentService.GetEntityById <DataAccess.DistributorTransfer>(updatedDistributorTransfer.Id); CheckHelper.NotNull(distributorTransfer, "Distributor Transfer does not exist."); CheckHelper.WithinCondition( distributorTransfer.CreateUserId == SecurityService.CurrentUser.Id, "Distributor can only change distributor transfer created by him."); distributorTransfer.Date = updatedDistributorTransfer.Date; distributorTransfer.Amount = updatedDistributorTransfer.Amount; distributorTransfer.Active = updatedDistributorTransfer.Active; distributorTransfer.RublesPerDollar = updatedDistributorTransfer.RublesPerDollar; distributorTransfer.UpdateTrackFields(Container); persistentService.SaveChanges(); }
public void CreateDistributorTransfer(DTO.DistributorTransfer createdDistributorTransfer) { CheckHelper.ArgumentNotNull(createdDistributorTransfer, "createdDistributorTransfer"); CheckHelper.ArgumentWithinCondition(createdDistributorTransfer.IsNew(), "Distributor Transfer is not new."); Container.Get <IValidateService>().CheckIsValid(createdDistributorTransfer); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserDistributor, "Only distributor can create distributor transfer."); var persistentService = Container.Get <IPersistentService>(); var distributorTransfer = new DataAccess.DistributorTransfer { Date = createdDistributorTransfer.Date, Amount = createdDistributorTransfer.Amount, Active = createdDistributorTransfer.Active, RublesPerDollar = createdDistributorTransfer.RublesPerDollar }; distributorTransfer.UpdateTrackFields(Container); persistentService.Add(distributorTransfer); persistentService.SaveChanges(); createdDistributorTransfer.Id = distributorTransfer.Id; createdDistributorTransfer.CreateDate = distributorTransfer.CreateDate; createdDistributorTransfer.CreateUser = distributorTransfer.CreatedBy.GetFullName(); createdDistributorTransfer.ChangeDate = distributorTransfer.ChangeDate; createdDistributorTransfer.ChangeUser = distributorTransfer.ChangedBy.GetFullName(); }
public static int GetHashCode <T>(T obj) where T : class { CheckHelper.ArgumentNotNull(obj, "obj"); var properties = GetProperties <T>(); int hashCode = 0; foreach (var property in properties) { if (property.GetCustomAttribute <IgnoreInGetHashCodeAttribute>() != null) { continue; } var value = property.GetValue(obj, null); if (value == null) { continue; } hashCode |= value.GetHashCode(); } return(hashCode); }
public DTO.SubCategory[] GetSubCategories(DTO.Category category, string filter) { CheckHelper.ArgumentNotNull(category, "category"); CheckHelper.ArgumentWithinCondition(!category.IsNew(), "!category.IsNew()"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can get all subcategories."); var query = Container .Get <IPersistentService>() .GetEntitySet <SubCategory>() .Where(sc => sc.CategoryId == category.Id) .AsQueryable(); if (!string.IsNullOrWhiteSpace(filter)) { query = query.Where(sc => sc.Name.Contains(filter)); } var dtoService = Container.Get <IDtoService>(); return (query .OrderBy(sc => sc.Id) .ToArray() .Select(sc => dtoService.CreateSubCategory(sc, false)) .ToArray()); }
public void UpdateCategory(DTO.Category updatedCategory) { CheckHelper.ArgumentNotNull(updatedCategory, "updatedCategory"); CheckHelper.ArgumentWithinCondition(!updatedCategory.IsNew(), "Category is new."); Container.Get <IValidateService>().CheckIsValid(updatedCategory); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can change category."); var persistentService = Container.Get <IPersistentService>(); var category = persistentService.GetEntityById <DataAccess.Category>(updatedCategory.Id); CheckHelper.NotNull(category, "Category does not exist."); if (category.Name != updatedCategory.Name) { var doesAnotherCategoryWithTheSameNameExist = persistentService .GetEntitySet <DataAccess.Category>() .Any(c => c.Name == updatedCategory.Name); if (doesAnotherCategoryWithTheSameNameExist) { throw new CategoryServiceException("Категория с заданным названием уже существует."); } } category.Name = updatedCategory.Name; category.Active = updatedCategory.Active; category.UpdateTrackFields(Container); persistentService.SaveChanges(); }
private static object[][] GetValuesByDtos <TDto>(TDto[] dtos, Func <TDto, object[]> getValuesByDto) where TDto : class, IDto, ICloneable, new() { CheckHelper.ArgumentNotNull(dtos, "dtos"); CheckHelper.ArgumentNotNull(getValuesByDto, "getValuesByDto"); if (dtos.Length == 0) { return new object[][] { } } ; var rows = new List <object[]>(dtos.Length); foreach (var dto in dtos) { var dtoValues = getValuesByDto(dto); var values = new object[] { dto.Id } .Concat(dtoValues) .ToArray(); rows.Add(values); } return(rows.ToArray()); }
public static Bitmap ResizeBitmap(this Bitmap sourceBitmap, int maxWidth, int maxHeight) { CheckHelper.ArgumentNotNull(sourceBitmap, "sourceBitmap"); CheckHelper.ArgumentWithinCondition(maxWidth >= 2, "maxWidth >= 2"); CheckHelper.ArgumentWithinCondition(maxHeight >= 2, "maxHeight >= 2"); var originalWidth = (double)sourceBitmap.Width; var originalHeight = (double)sourceBitmap.Height; var longestDimension = Math.Max(originalWidth, originalHeight); var shortestDimension = Math.Min(originalWidth, originalHeight); var factor = longestDimension / shortestDimension; var newWidth = originalWidth < originalHeight ? (int)(maxHeight / factor) : maxWidth; var newHeight = originalWidth < originalHeight ? maxHeight : (int)(maxWidth / factor); var resizedBitmap = new Bitmap(newWidth, newHeight); using (var graphics = Graphics.FromImage(resizedBitmap)) graphics.DrawImage(sourceBitmap, 0, 0, newWidth, newHeight); return(resizedBitmap); }
public TDto Get <TDto, TEntity>(TEntity entity, Func <TEntity, TDto> create, Action <TDto, TEntity> initialize = null) where TDto : class, IDto where TEntity : class, IEntity { CheckHelper.ArgumentNotNull(entity, "entity"); CheckHelper.WithinCondition(!entity.IsNew(), "!entity.IsNew()"); CheckHelper.ArgumentNotNull(create, "create"); var dtoType = typeof(TDto); var id = entity.Id; IDictionary <int, IDto> dtoObjects; if (!_dtoCache.TryGetValue(dtoType, out dtoObjects)) { dtoObjects = new Dictionary <int, IDto>(); _dtoCache.Add(dtoType, dtoObjects); } IDto dtoObject; if (!dtoObjects.TryGetValue(id, out dtoObject)) { dtoObject = create(entity); dtoObjects.Add(id, dtoObject); if (initialize != null) { initialize((TDto)dtoObject, entity); } } return((TDto)dtoObject); }
public SubCategory[] GetSubCategories(string filter, Category category) { CheckHelper.ArgumentNotNull(category, "category"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "SecurityService.IsLoggedIn"); return(APIClientHelper <DictionaryAPIClient> .Call(c => c.GetSubCategoriesByCategory(category, filter))); }
public ValidateException(IValidateErrors <T> errors) : base(errors.ToExceptionMessage()) { CheckHelper.ArgumentNotNull(errors, "errors"); Errors = errors; }
public void LogIn(DTO.SecurityData securityData) { CheckHelper.ArgumentNotNull(securityData, "securityData"); CheckHelper.ArgumentNotNullAndNotWhiteSpace(securityData.Login, "securityData.Login"); CheckHelper.ArgumentNotNullAndNotWhiteSpace(securityData.Password, "securityData.Password"); CheckHelper.ArgumentWithinCondition(securityData.Login != DTO.User.GUEST_LOGIN, "To log in as a guest use LogInGuest method."); CheckHelper.WithinCondition(!IsLoggedIn, "User is already logged in."); var persistentService = Container.Get <IPersistentService>(); var user = persistentService .GetEntitySet <User>() .SingleOrDefault(u => u.Login == securityData.Login); if (user == null) { throw new SecurityServiceException("Пользователь с заданным логином и паролем не существует."); } if (!user.Active) { throw new SecurityServiceException("Пользователь с заданным логином отключен администратором."); } var passwordData = Container.Get <IEncryptService>().EncryptPassword(securityData.Password, user.PasswordSalt); if (passwordData.PasswordHash != user.PasswordHash) { throw new SecurityServiceException("Пользователь с заданным логином и паролем не существует."); } var dtoService = Container.Get <IDtoService>(); _currentUser = dtoService.CreateUser(user); }
public DTO.Size CreateSize(DataAccess.Size size, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(size, "size"); CheckHelper.ArgumentWithinCondition(!size.IsNew(), "!size.IsNew()"); return (_dtoCache.Get( size, s => { var result = new DTO.Size { Id = s.Id, Name = s.Name, Height = s.Height, Weight = s.Weight, Active = s.Active }; CopyTrackableFields(result, s); return result; }, (sDto, s) => { sDto.Brand = CreateBrand(s.Brand, includeOnlyActive); sDto.SubCategory = CreateSubCategory(s.SubCategory, includeOnlyActive); })); }
public void UpdateSettings(DTO.Settings updatedSettings) { CheckHelper.ArgumentNotNull(updatedSettings, "updatedSettings"); CheckHelper.ArgumentWithinCondition(!updatedSettings.IsNew(), "!updatedSettings.IsNew()"); Container.Get <IValidateService>().CheckIsValid(updatedSettings); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserAdministrator, "Only administrator can update settings."); var persistentService = Container.Get <IPersistentService>(); var settings = Container .Get <IPersistentService>() .GetEntitySet <DataAccess.Settings>() .SingleOrDefault(); CheckHelper.ArgumentNotNull(settings, "Cannot find settings."); CheckHelper.WithinCondition(settings.Id == updatedSettings.Id, "settings.Id == updatedSettings.Id"); settings.RublesPerDollar = updatedSettings.RublesPerDollar; settings.UpdateTrackFields(Container); persistentService.SaveChanges(); _settings = null; }
public DTO.OrderItem CreateOrderItem(DataAccess.OrderItem orderItem, bool includeOnlyActive = false, Func <DataAccess.Order, bool> predicate = null) { CheckHelper.ArgumentNotNull(orderItem, "orderItem"); CheckHelper.ArgumentWithinCondition(!orderItem.IsNew(), "!orderItem.IsNew()"); return (_dtoCache.Get( orderItem, oi => { var result = new DTO.OrderItem { Id = oi.Id, Quantity = oi.Quantity, Active = oi.Active, Price = oi.Price, PurchaserPaid = oi.PurchaserPaid, CreateUserId = oi.CreateUserId }; CopyTrackableFields(result, oi); return result; }, (oiDto, oi) => { oiDto.Order = CreateOrder(oi.Order, includeOnlyActive, predicate); oiDto.ProductSize = CreateProductSize(oi.ProductSize); })); }
public OrderItem[] GetOrderItems(Order order) { CheckHelper.ArgumentNotNull(order, "order"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "SecurityService.IsLoggedIn"); return(APIClientHelper <DocumentAPIClient> .Call(c => c.GetOrderItems(order))); }
public DTO.Category CreateCategory(DataAccess.Category category, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(category, "category"); CheckHelper.ArgumentWithinCondition(!category.IsNew(), "!category.IsNew()"); return (_dtoCache.Get( category, c => { var result = new DTO.Category { Id = c.Id, Name = c.Name, Active = c.Active }; CopyTrackableFields(result, c); return result; }, (cDto, c) => cDto.SubCategories = c.SubCategories .Where(sc => sc.Active || !includeOnlyActive) .OrderBy(sc => sc.Name) .Select(sc => CreateSubCategory(sc, includeOnlyActive)) .ToArray())); }
public Order[] GetOrders(Parcel parcel, string filter) { CheckHelper.ArgumentNotNull(parcel, "parcel"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "SecurityService.IsLoggedIn"); return(APIClientHelper <DocumentAPIClient> .Call(c => c.GetOrdersByParcel(parcel, filter))); }
private FaultException GetFaultException(Exception error) { CheckHelper.ArgumentNotNull(error, "error"); var faultException = error as FaultException; if (faultException != null) { return(faultException); } const string REASON = "Server error."; if (IsUserLoggedIn()) { var exceptionData = new ErrorData { Message = error.Message, UtcTime = DateTime.UtcNow, StackTrace = error.StackTrace, ExceptionType = error.GetType().ToString() }; return(new FaultException <ErrorData>(exceptionData, REASON)); } return(new FaultException(REASON)); }
private string SaveResizedImage(Bitmap bitmap, string fileName, int maxWidth, int maxHeight) { CheckHelper.ArgumentNotNull(bitmap, "bitmap"); CheckHelper.ArgumentNotNullAndNotWhiteSpace(fileName, "fileName"); var imagesDirectoryPath = GetImageDirectoryPath(); if (!Directory.Exists(imagesDirectoryPath)) { Directory.CreateDirectory(imagesDirectoryPath); } var fullPicturePath = Path.Combine(imagesDirectoryPath, fileName); CheckHelper.WithinCondition(!File.Exists(fullPicturePath), string.Format("File {0} already exists.", fileName)); var imagesDirectoryUrl = GetImageDirectoryUrl(); using (var resizedBitmap = bitmap.ResizeBitmap(maxWidth, maxHeight)) { resizedBitmap.Save(fullPicturePath, ImageFormat.Jpeg); return(UrlHelper.Combine(imagesDirectoryUrl, fileName)); } }
public ProductSize[] GetProductSizes(DTO.Product product, string filter) { CheckHelper.ArgumentNotNull(product, "product"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); return(APIClientHelper <ProductAPIClient> .Call(c => c.GetProductSizesByProduct(product, filter))); }
internal static void RegisterAssemblyTypes(IContainer container) { CheckHelper.ArgumentNotNull(container, "container"); container.SetImplementation <IActionLogService, ActionLogService>(Lifetime.PerContainer); container.SetImplementation <IConfigurationService, ConfigurationService>(Lifetime.PerContainer); container.SetImplementation <INotificationService, NotificationService>(Lifetime.PerContainer); container.SetImplementation <ISettingsService, SettingsService>(Lifetime.PerContainer); container.SetImplementation <IImageService, ImageService>(Lifetime.PerContainer); container.SetImplementation <IDtoCache, DtoCache>(); container.SetImplementation <IDtoService, DtoService>(); container.SetImplementation <IPasswordGeneratorService, PasswordGeneratorService>(Lifetime.PerContainer); container.SetImplementation <ISecurityService, SecurityService>(Lifetime.PerContainer); container.SetImplementation <ICategoryService, CategoryService>(Lifetime.PerContainer); container.SetImplementation <IBrandService, BrandService>(Lifetime.PerContainer); container.SetImplementation <ISizeService, SizeService>(Lifetime.PerContainer); container.SetImplementation <IProductSizeService, ProductSizeService>(Lifetime.PerContainer); container.SetImplementation <IProductService, ProductService>(Lifetime.PerContainer); container.SetImplementation <IOrderService, OrderService>(Lifetime.PerContainer); container.SetImplementation <IParcelService, ParcelService>(Lifetime.PerContainer); container.SetImplementation <IHttpService, HttpService>(Lifetime.PerContainer); container.SetImplementation <IDistributorTransferService, DistributorTransferService>(Lifetime.PerContainer); container.SetImplementation <IReportService, ReportService>(Lifetime.PerContainer); container.SetImplementation <ILogService, LogService>(Lifetime.PerContainer); }