Beispiel #1
0
        /// <summary>
        /// Gets the by identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public Product GetById(int id)
        {
            using (DataModelEntities model = new DataModelEntities())
            {
                var retVal = model.Product
                             .Include(p => p.ProductType)
                             .Include(p => p.Rating)
                             .Include(p => p.Item)
                             .Include(p => p.State)
                             .Include(p => p.CreateOperator)
                             .Include(p => p.Customer)
                             .Include(p => p.PaperReference)
                             .Include(p => p.City)
                             .Include(p => p.City.Country)
                             .Include(p => p.Customer.CustomerType)
                             .Include(p => p.SellingOperator)
                             .Include(p => p.Categories)
                             .Include(p => p.Brands)
                             .Include(p => p.Models)
                             .FirstOrDefault(p => p.Id.Equals(id));

                return(retVal);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="extension">The extension.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <param name="content">The content.</param>
        /// <param name="productId">The product identifier.</param>
        /// <returns></returns>
        public Attachment Create(string fileName, string extension, string mimeType, byte[] content, int productId)
        {
            using (DataModelEntities model = new DataModelEntities())
            {
                Attachment retVal = null;

                if (model.Product.Any(p => p.Equals(productId)))
                {
                    retVal = new Attachment
                    {
                        FileName  = fileName,
                        Extension = extension,
                        MimeType  = mimeType,
                        Content   = content,
                        ProductId = productId
                    };

                    model.Attachment.AddObject(retVal);
                    model.SaveChanges();
                }

                return(retVal);
            }
        }
Beispiel #3
0
 public AppDataAccess(LoadDataGridViewAsync form)
 {
     this.callingForm = form;
     db = new DataModelEntities();
 }
Beispiel #4
0
        /// <summary>
        /// Saves the basic information.
        /// </summary>
        /// <param name="productId">The product identifier.</param>
        /// <param name="name">The name.</param>
        /// <param name="productTypeId">The category identifier.</param>
        /// <param name="itemId">The item identifier.</param>
        /// <param name="paperReferenceId">The paper reference identifier.</param>
        /// <param name="locationId">The location identifier.</param>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="operatorId">The operator identifier.</param>
        /// <param name="ratingId">The rating identifier.</param>
        /// <param name="yearIds">The year ids.</param>
        /// <param name="depositDate">The deposit date.</param>
        /// <returns></returns>
        public Product SaveBasicInfo(int productId, string name, int productTypeId, int itemId, int locationId, int customerId, int operatorId, int[] categoryIds, int[] brandIds, int[] modelIds,
                                     int[] yearIds, int stateId, decimal buyinPrice, DateTime depositDate)
        {
            using (DataModelEntities dataModel = new DataModelEntities())
            {
                var product = dataModel.Product.FirstOrDefault(p => p.Id.Equals(productId));

                if (product != null)
                {
                    product.Name           = name;
                    product.ProductTypeId  = productTypeId;
                    product.ItemId         = itemId;
                    product.LocationId     = locationId;
                    product.CustomerId     = customerId;
                    product.OperatorId     = operatorId;
                    product.DepositBuyDate = depositDate;
                    product.BuyingPrice    = buyinPrice;
                    product.StateId        = stateId;
                    product.ProductYear.Clear();
                    product.StatusId = (int)Enums.ProductStatus.New;

                    dataModel.SaveChanges();

                    foreach (var yearId in yearIds)
                    {
                        product.ProductYear.Add(new ProductYear {
                            YearId = yearId
                        });
                    }

                    dataModel.SaveChanges();
                }
                else
                {
                    product = new Product
                    {
                        Name           = name,
                        ProductTypeId  = productTypeId,
                        ItemId         = itemId,
                        LocationId     = locationId,
                        CustomerId     = customerId,
                        OperatorId     = operatorId,
                        DepositBuyDate = depositDate,
                        StateId        = stateId,
                        BuyingPrice    = buyinPrice,
                        StatusId       = (int)Enums.ProductStatus.Sold
                    };

                    foreach (var yearId in yearIds)
                    {
                        product.ProductYear.Add(new ProductYear {
                            YearId = yearId
                        });
                    }

                    dataModel.Product.AddObject(product);
                }

                foreach (var categoryId in categoryIds)
                {
                    product.Categories.Add(dataModel.Category.FirstOrDefault(c => c.Id.Equals(categoryId)));
                }

                foreach (var brandId in brandIds)
                {
                    product.Brands.Add(dataModel.Brand.FirstOrDefault(b => b.Id.Equals(brandId)));
                }

                foreach (var modelId in modelIds)
                {
                    product.Models.Add(dataModel.Model.FirstOrDefault(m => m.Id.Equals(modelId)));
                }

                dataModel.SaveChanges();
                return(this.GetById(product.Id));
            }
        }