public void CreateProduct(DTO.Product createdProduct) { CheckHelper.ArgumentNotNull(createdProduct, "createdProduct"); CheckHelper.ArgumentWithinCondition(createdProduct.IsNew(), "Product is not new."); Container.Get<IValidateService>().CheckIsValid(createdProduct); CheckHelper.ArgumentWithinCondition(!createdProduct.SubCategory.IsNew(), "SubCategory of Product is new."); CheckHelper.ArgumentWithinCondition(!createdProduct.Brand.IsNew(), "Brand of Product is new."); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can create product."); var persistentService = Container.Get<IPersistentService>(); var subCategory = persistentService.GetEntityById<SubCategory>(createdProduct.SubCategory.Id); CheckHelper.NotNull(subCategory, "SubCategory does not exist."); var brand = persistentService.GetEntityById<DataAccess.Brand>(createdProduct.Brand.Id); CheckHelper.NotNull(brand, "Brand does not exist."); var httpService = Container.Get<IHttpService>(); var product = new DataAccess.Product { Name = createdProduct.Name, SubCategoryId = subCategory.Id, SubCategory = subCategory, BrandId = brand.Id, Brand = brand, Active = brand.Active, Description = createdProduct.Description, VendorShopURL = createdProduct.VendorShopURL, FullPictureURL = httpService.GetRelativeURLFromAbsoluteURL(createdProduct.FullPictureURL), PreviewPictureURL = httpService.GetRelativeURLFromAbsoluteURL(createdProduct.PreviewPictureURL) }; product.UpdateTrackFields(Container); persistentService.Add(product); persistentService.SaveChanges(); createdProduct.Id = product.Id; createdProduct.CreateDate = product.CreateDate; createdProduct.CreateUser = product.CreatedBy.GetFullName(); createdProduct.ChangeDate = product.ChangeDate; createdProduct.ChangeUser = product.ChangedBy.GetFullName(); }