Example #1
0
        public static void AddLot(Lot lot, AuctionEntities au)
        {
            if (lot.IdLot == 0)
            {
                au.Lots.Add(lot);
            }
            else
            {
                Lot dbLot = au.Lots.Find(lot.IdLot);
                if (dbLot != null)
                {
                    dbLot.IdSection = lot.IdSection;
                    dbLot.Name = lot.Name;
                    dbLot.Description = lot.Description;
                    dbLot.StartDate = lot.StartDate;
                    dbLot.EndDate = lot.EndDate;
                    dbLot.StartPrice = lot.StartPrice;
                    dbLot.Tick = lot.Tick;
                    dbLot.CurrentPrice = lot.CurrentPrice;
                    dbLot.Status = lot.Status;
                    dbLot.Img = lot.Img;

                }
            }
        }
Example #2
0
 public static void AddUser(User user)
 {
     using (AuctionEntities au = new AuctionEntities())
     {
         if (user.Id == 0)
         {
             au.Users.Add(user);
         }
         else
         {
             User dbUser = au.Users.Find(user.Id);
             if (dbUser != null)
             {
                 dbUser.IdRole = user.IdRole;
                 dbUser.Login = user.Login;
                 dbUser.Password = user.Password;
                 dbUser.Email = user.Email;
                 dbUser.Phone = user.Phone;
                 dbUser.Name = user.Name;
                 dbUser.Address = user.Address;
             }
         }
         au.SaveChanges();
     }
 }
Example #3
0
        private void NotifyAuctionEnd(Guid itemId)
        {
            var context = new AuctionEntities();

            var item = context.Items.Find(itemId);

            item.IsAvailable = false;

            if (item.BuyerId != null)
            {
                var sellerEmail = context.Accounts.Find(item.SellerId).Email;
                context.Notifications.Add(new Notification
                {
                    Id         = Guid.NewGuid(),
                    Message    = "Auction has been finished, you've purchased the product!\nPlease contact seller via email: " + sellerEmail,
                    ReceiverId = item.BuyerId.Value
                });
            }

            context.Notifications.Add(new Notification
            {
                Id         = Guid.NewGuid(),
                Message    = "Auction has been finished!\nPlease contact buyer via email: " + item.BuyerAccount.Email,
                ReceiverId = item.SellerId
            });

            context.SaveChanges();
        }
Example #4
0
        public static void AddSection(Section section)
        {
            using (AuctionEntities au = new AuctionEntities())
            {
                if (section.Id == 0)
                {
                    au.Sections.Add(section);
                }
                else
                {
                    Section dbSection = au.Sections.Find(section.Id);
                    if (dbSection != null)
                    {
                        dbSection.NameSection = section.NameSection;

                    }
                }
                au.SaveChanges();
            }
        }
Example #5
0
 public BaseController()
 {
     this.DbContext = new AuctionEntities();
 }
 public AuctionEntities Get()
 {
     return context ?? (context = new AuctionEntities());
 }
Example #7
0
 public static void AddUserLot(UserLot userLot, AuctionEntities au)
 {
     if (userLot.Id == 0)
     {
         au.UserLots.Add(userLot);
     }
     else
     {
         UserLot dbUserLot = au.UserLots.Find(userLot.Id);
         if (dbUserLot != null)
         {
             dbUserLot.IdUser = userLot.IdUser;
             dbUserLot.IdLot = userLot.IdLot;
             dbUserLot.idStatus = userLot.idStatus;
         }
     }
 }
Example #8
0
        public static void UpdateLotsStatus()
        {
            using (AuctionEntities au = new AuctionEntities())
            {
                IEnumerable<Lot> lots = au.Lots
                .Where(l => l.EndDate <= DateTime.Now && l.Status != false).ToList();

                if (lots.Any())
                {
                    foreach (Lot lot in lots)
                    {
                        lot.Status = false;
                        AddLot(lot, au);
                    }
                }

                IEnumerable<UserLot> userLots = au.UserLots
                .Where(ul => ul.Lot.Status == false).ToList();

                if (userLots.Any())
                {
                    foreach (UserLot userLot in userLots)
                    {
                        if (userLot.idStatus == 1)
                        {
                            userLot.idStatus = 4;
                            AddUserLot(userLot, au);
                        }
                        if (userLot.idStatus == 2)
                        {
                            userLot.idStatus = 5;
                            AddUserLot(userLot, au);
                        }
                    }
                }
                au.SaveChanges();
            }
        }
 public AuctionEntities Get()
 {
     return(context ?? (context = new AuctionEntities()));
 }
Example #10
0
 public AuctionService(AuctionEntities auctionEntities)
 {
     _auctionEntities = auctionEntities;
 }