コード例 #1
0
        public void Save(string userId = null)
        {
            if (Order.OrderNumber == 0)
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    db.OrderHeaders.Add(Order);
                    db.SaveChanges();
                }
            }

            // Compare the Session cart to the database cart and resolve differences
            Compare();

            // Re-initialize the Body
            Body = CartBody.GetDetailsForShoppingCart(Order.OrderNumber);

            // Keep the total order value in sync
            UpdateTotal();

            // Save the Order total
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                db.Entry(Order).State = EntityState.Modified;
                db.SaveChanges();
            }

            AuditUser.LogAudit(6, string.Format("Order number: {0}", Order.OrderNumber), userId);
        }
コード例 #2
0
        private FreeMarketResult RemoveItemFromDatabase(int itemNumber, string userId = null)
        {
            FreeMarketResult result = FreeMarketResult.NoResult;

            if (itemNumber != 0)
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    OrderDetail item = db.OrderDetails.Find(itemNumber);

                    if (item != null)
                    {
                        FreeStock(item.ProductNumber, item.SupplierNumber, (int)item.CustodianNumber, item.Quantity, item.SizeType);

                        db.OrderDetails.Remove(item);
                        db.SaveChanges();

                        AuditUser.LogAudit(8, string.Format("Order number: {0}", Order.OrderNumber), userId);

                        result = FreeMarketResult.Success;
                    }
                    else
                    {
                        result = FreeMarketResult.Failure;
                    }
                }
            }
            else
            {
                result = FreeMarketResult.Success;
            }

            return(result);
        }
コード例 #3
0
        public static FreeMarketResult UpdateAddress(string userId, string addressName, string addressLine1, string addressLine2,
                                                     string addressLine3, string addressLine4, string addressSuburb, string addressCity, string addressPostalCode)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                CustomerAddress address = db.CustomerAddresses
                                          .Where(c => c.CustomerNumber == userId && c.AddressName == addressName)
                                          .FirstOrDefault();

                if (address == null)
                {
                    return(FreeMarketResult.Failure);
                }

                address.AddressLine1      = addressLine1;
                address.AddressLine2      = addressLine2;
                address.AddressLine3      = addressLine3;
                address.AddressLine4      = addressLine4;
                address.AddressCity       = addressCity;
                address.AddressPostalCode = addressPostalCode;
                address.AddressSuburb     = addressSuburb;

                db.Entry(address).State = EntityState.Modified;
                db.SaveChanges();

                AuditUser.LogAudit(5, string.Format("Address name: {0}", addressName), userId);
            }

            return(FreeMarketResult.Success);
        }
コード例 #4
0
        public static FreeMarketResult AddAddress(string userId, string addressName, string addressLine1, string addressLine2,
                                                  string addressLine3, string addressLine4, string addressSuburb, string addressCity, string addressPostalCode)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                CustomerAddress address = new CustomerAddress()
                {
                    CustomerNumber    = userId,
                    AddressName       = addressName,
                    AddressLine1      = addressLine1,
                    AddressLine2      = addressLine2,
                    AddressLine3      = addressLine3,
                    AddressLine4      = addressLine4,
                    AddressCity       = addressCity,
                    AddressPostalCode = addressPostalCode,
                    AddressSuburb     = addressSuburb
                };

                db.CustomerAddresses.Add(address);
                db.SaveChanges();

                AuditUser.LogAudit(5, string.Format("Address name: {0}", addressName), userId);
            }

            return(FreeMarketResult.Success);
        }
コード例 #5
0
        public void Compare()
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                // Get a list of items which are on both the Session and database
                List <OrderDetail> existingItems = Body.OrderDetails.FindAll(c => c.ItemNumber != 0);

                if (existingItems != null && existingItems.Count > 0)
                {
                    foreach (OrderDetail temp in existingItems)
                    {
                        OrderDetail tempDb = db.OrderDetails.Find(temp.ItemNumber);

                        if (tempDb != null)
                        {
                            if (!temp.Equals(tempDb))
                            {
                                // If the item has changed update it
                                tempDb.Quantity       = temp.Quantity;
                                tempDb.OrderItemValue = temp.OrderItemValue;

                                db.Entry(tempDb).State = EntityState.Modified;
                                db.SaveChanges();

                                AuditUser.LogAudit(7, string.Format("Order number: {0}", Order.OrderNumber));
                            }
                        }
                    }
                }

                // Get a list of items that are on the Session variable but not in the database
                List <OrderDetail> newItems = Body.OrderDetails.FindAll(c => c.ItemNumber == 0);

                if (newItems != null && newItems.Count > 0)
                {
                    foreach (OrderDetail tempB in newItems)
                    {
                        tempB.OrderNumber = Order.OrderNumber;

                        ReserveStock(tempB.ProductNumber, tempB.SupplierNumber, (int)tempB.CustodianNumber, tempB.Quantity, tempB.SizeType);

                        db.OrderDetails.Add(tempB);
                    }

                    db.SaveChanges();

                    AuditUser.LogAudit(7, string.Format("Order number: {0}", Order.OrderNumber));
                }

                // Ensure the latest prices are used
                UpdatePrices();
            }
        }
コード例 #6
0
        public static void LogAudit(short action, string parameters, string userId = null)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                string user = userId ?? "Anonymous";

                if (ExceptionLogging.AuditLoggingEnabled())
                {
                    AuditUser audit = new AuditUser()
                    {
                        Identity   = user,
                        DateTime   = DateTime.Now,
                        Action     = action,
                        Parameters = parameters
                    };

                    db.AuditUsers.Add(audit);
                    db.SaveChanges();
                }
            }
        }
コード例 #7
0
        public static FreeMarketResult SaveDepartmentImage(int departmentNumber, PictureSize size, HttpPostedFileBase image)
        {
            if (image != null && departmentNumber != 0)
            {
                using (FreeMarketEntities db = new FreeMarketEntities())
                {
                    DepartmentPicture picture = new DepartmentPicture();

                    Department department = db.Departments.Find(departmentNumber);

                    if (department == null)
                    {
                        return(FreeMarketResult.Failure);
                    }

                    picture = db.DepartmentPictures
                              .Where(c => c.DepartmentNumber == departmentNumber && c.Dimensions == size.ToString())
                              .FirstOrDefault();

                    try
                    {
                        // No picture exists for this dimension/product
                        if (picture == null)
                        {
                            picture            = new DepartmentPicture();
                            picture.Picture    = new byte[image.ContentLength];
                            picture.Annotation = department.DepartmentName;
                            picture.Dimensions = size.ToString();
                            image.InputStream.Read(picture.Picture, 0, image.ContentLength);
                            picture.PictureMimeType  = image.ContentType;
                            picture.DepartmentNumber = departmentNumber;

                            db.DepartmentPictures.Add(picture);
                            db.SaveChanges();

                            AuditUser.LogAudit(9, string.Format("Department: {0}", departmentNumber));
                            return(FreeMarketResult.Success);
                        }
                        else
                        {
                            picture.Annotation = department.DepartmentName;
                            picture.Picture    = new byte[image.ContentLength];
                            image.InputStream.Read(picture.Picture, 0, image.ContentLength);
                            picture.PictureMimeType = image.ContentType;

                            db.Entry(picture).State = EntityState.Modified;
                            db.SaveChanges();

                            AuditUser.LogAudit(9, string.Format("Department: {0}", departmentNumber));
                            return(FreeMarketResult.Success);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionLogging.LogException(e);
                        return(FreeMarketResult.Failure);
                    }
                }
            }

            return(FreeMarketResult.Failure);
        }