Example #1
0
 public void UpdateBox(DTOs.Box boxes, int id)
 {
     DTOs.Box            boxe = GetById(id);
     usersWebService.Box box  = new usersWebService.Box();
     box.ID = (int)boxe.ID;
     context.Box.Remove(box);
     box.ID          = (int)boxes.ID;
     box.Name        = boxes.Name;
     box.Price       = boxes.Price;
     box.Description = boxes.Description;
     // box.Contents = boxes.Contents;
     box.Visible   = boxes.Visible;
     box.Available = boxes.Available;
     context.Box.Add(box);
     Save();
 }
Example #2
0
 public bool CreateBox(DTOs.Box boxes)
 {
     if (boxes.Price < 5 || boxes.Price > 25)
     {
         return(false);
     }
     else
     {
         usersWebService.Box box = new usersWebService.Box();
         box.ID          = (int)boxes.ID;
         box.Name        = boxes.Name;
         box.Price       = boxes.Price;
         box.Description = boxes.Description;
         // box.Contents = boxes.Contents;
         box.Visible   = boxes.Visible;
         box.Available = boxes.Available;
         context.Box.Add(box);
         return(true);
     }
 }
Example #3
0
        public DTOs.Box GetById(int id)
        {
            var data = context.Box.ToList();

            DTOs.Box boxes = data.Where(b => b.ID == id).Select(b => new DTOs.Box
                                                                (
                                                                    ID: b.ID,
                                                                    Name: b.Name,
                                                                    Price: b.Price,
                                                                    Description: b.Description,
                                                                    // Contents = b.Contents,
                                                                    Visible: b.Visible,
                                                                    Available: b.Available
                                                                )).FirstOrDefault();
            boxes.Contents = GetItemsForBox(id);
            bool    Available = true;
            decimal price     = 0;

            foreach (DTOs.Product product in boxes.Contents)
            {
                if (product.InStock == false)
                {
                    Available = false;
                    price     = price + product.Price;
                }
            }

            if ((price * 0.1m + price) < (decimal)boxes.Price)
            {
                boxes.Available = false;
            }
            else
            {
                boxes.Available = Available;
            }

            return(boxes);
        }