Ejemplo n.º 1
0
        public RepositoryActionResult <DataAccess.Product> UpdateProduct(DataAccess.Product e)
        {
            try
            {
                var Id = Guid.Parse(e.Id.ToString().ToLower());
                var existingProduct = _context.Products.FirstOrDefault(p => p.Id == Id);
                Trace.WriteLine(Id);
                if (existingProduct == null)
                {
                    return(new RepositoryActionResult <Product>(e, RepositoryActionStatus.NotFound));
                }

                _context.Entry(existingProduct).State = EntityState.Detached;

                _context.Products.Attach(e);

                _context.Entry(e).State = EntityState.Modified;


                var result = _context.SaveChanges();
                if (result > 0)
                {
                    return(new RepositoryActionResult <Product>(e, RepositoryActionStatus.Updated));
                }
                else
                {
                    return(new RepositoryActionResult <Product>(e, RepositoryActionStatus.NothingModified, null));
                }
            }
            catch (Exception ex)
            {
                return(new RepositoryActionResult <Product>(null, RepositoryActionStatus.Error, ex));
            }
        }
Ejemplo n.º 2
0
        public static void Reset()
        {
            _theChildrensPlace_Boys_Sweater = null;
            _carters_Boys_Shorts            = null;
            _theChildrensPlace_Boys_TShirt  = null;
            _theChildrensPlace_Boys_Sweater = null;
            _theChildrensPlace_Girls_Shorts = null;

            _products = null;
        }
Ejemplo n.º 3
0
        public DataAccess.Product Calculate(DataAccess.Product product)
        {
            foreach (var category in product.Category)
            {
                product.Tax += Math.Round((product.Price * taxesViaCategory[category]) / 0.05d, 0) * 0.05d;
            }

            product.Total = product.Price + product.Tax;

            return(product);
        }
Ejemplo n.º 4
0
 public static ProductViewModel ToQueryViewModel(this DataAccess.Product entity,
                                                 ProductViewModel model)
 {
     model.SessionUserId     = entity.CreatedUserId;
     model.Id                = entity.Id;
     model.Name              = entity.Name;
     model.Description       = entity.Description;
     model.Ordinal           = entity.Ordinal;
     model.IsActive          = entity.IsActive;
     model.Price             = entity.Price;
     model.ProductCategory   = entity.ProductCategory.Name;
     model.ProductCategoryId = entity.ProductCategoryId;
     model.ProductImages     = entity.ProductImages.AsQueryable().ToQueryListViewModel();
     return(model);
 }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
 public RepositoryActionResult <DataAccess.Product> InsertProduct(DataAccess.Product e)
 {
     try
     {
         _context.Products.Add(e);
         var result = _context.SaveChanges();
         if (result > 0)
         {
             return(new RepositoryActionResult <Product>(e, RepositoryActionStatus.Created));
         }
         else
         {
             return(new RepositoryActionResult <Product>(e, RepositoryActionStatus.NothingModified, null));
         }
     }
     catch (Exception ex)
     {
         return(new RepositoryActionResult <Product>(null, RepositoryActionStatus.Error, ex));
     }
 }
Ejemplo n.º 7
0
        public DTO.Product CreateProduct(DataAccess.Product product, bool includeOnlyActive = true)
        {
            CheckHelper.ArgumentNotNull(product, "product");
            CheckHelper.ArgumentWithinCondition(!product.IsNew(), "!product.IsNew()");

            return
                (_dtoCache.Get(
                     product,
                     p =>
            {
                var httpService = Container.Get <IHttpService>();

                var result =
                    new DTO.Product
                {
                    Id = p.Id,
                    Name = p.Name,
                    Description = p.Description,
                    PreviewPictureURL = httpService.GetAbsoluteURLFromRelativeURL(p.PreviewPictureURL),
                    FullPictureURL = httpService.GetAbsoluteURLFromRelativeURL(p.FullPictureURL),
                    VendorShopURL = p.VendorShopURL,
                    Active = p.Active
                };

                CopyTrackableFields(result, p);

                return result;
            },
                     (pDto, p) =>
            {
                pDto.Brand = CreateBrand(p.Brand, includeOnlyActive);
                pDto.SubCategory = CreateSubCategory(p.SubCategory, includeOnlyActive);
                pDto.ProductSizes =
                    p.ProductSizes
                    .Where(ps => ps.Active || !includeOnlyActive)
                    .OrderBy(ps => ps.Size.Name)
                    .Select(ps => CreateProductSize(ps, includeOnlyActive))
                    .ToArray();
            }));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Convert ProductViewModel Object into Product Entity
        /// </summary>
        ///<param name="model">ProductViewModel</param>
        ///<param name="RegionEntity">DataAccess.Product</param>
        ///<returns>DataAccess.Product</returns>
        public static DataAccess.Product ToEntity(this ProductViewModel model,
                                                  DataAccess.Product entity)
        {
            if (entity.Id == 0)
            {
                entity.CreatedUserId = model.SessionUserId;
            }
            else
            {
                entity.IsActive         = model.IsActive;
                entity.UpdatedUserId    = model.SessionUserId;
                entity.UpdatedTimestamp = DateTime.Now;
            }

            entity.Name              = model.Name;
            entity.Description       = model.Description;
            entity.ProductCategoryId = model.ProductCategoryId;
            entity.Ordinal           = model.Ordinal;
            entity.Price             = model.Price;

            return(entity);
        }
Ejemplo n.º 9
0
 public static Products Map(DataAccess.Product product) => new Products
 {
     ProdId = product.Id,
     Name   = product.Name,
     Price  = (decimal)product.Price
 };
Ejemplo n.º 10
0
 ProductService()
 {
     product = new DataAccess.Product();
 }
Ejemplo n.º 11
0
 public DataTable ReturnSt()
 {
     DataAccess.Product proobj = new DataAccess.Product();
     return proobj.retStatus();
 }
Ejemplo n.º 12
0
 public IList<tblProduct> RetSearch(string key)
 {
     DataAccess.Product proobj = new DataAccess.Product();
     return proobj.Search(key);
 }