예제 #1
0
파일: BLL.cs 프로젝트: Zizaveta/LotsMaster
 public static string TellMeAboutStartLot(Person person, int lotId)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             db.Persons.Attach(person);
             if (db.Lots.First(elem => elem.Id == lotId).TimeStart <= DateTime.Now)
             {
                 return("Lot was started");
             }
             if (db.Tells.FirstOrDefault(elem => elem.Lot.Id == lotId && elem.Person.Id == person.Id) == null)
             {
                 db.Tells.Add(new Tell()
                 {
                     Person = person, Lot = db.Lots.First(elem => elem.Id == lotId)
                 });
                 db.SaveChanges();
             }
             return("You will know about start event");
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return("Something wrong in db");
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            using (DAL.AuctionContent db = new AuctionContent())
            {
                db.Persons.Add(new Person()
                {
                    FirstName = "asd",
                    Password  = "******",
                }
                               );

                db.SaveChanges();
            }
        }
예제 #3
0
파일: BLL.cs 프로젝트: Zizaveta/LotsMaster
 public static string ChangeSecondName(int PersonId, string Name)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             db.Persons.First(elem => elem.Id == PersonId).SecondName = Name;
             db.SaveChanges();
             return("Name is change");
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return("Wrong in db");
     }
 }
예제 #4
0
파일: BLL.cs 프로젝트: Zizaveta/LotsMaster
 public static string ChangePassword(int PersonId, string NewPassword)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             db.Persons.First(elem => elem.Id == PersonId).Password = NewPassword;
             db.SaveChanges();
             return("Password is change");
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return("Wrong in db");
     }
 }
예제 #5
0
 public static bool AddLot(Lot lot)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             db.Lots.Add(lot);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return(false);
     }
 }
예제 #6
0
파일: BLL.cs 프로젝트: Zizaveta/LotsMaster
 public static bool AddLot(Lot lot, Person p)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             db.Persons.Attach(p);
             lot.WhoSale = p;
             db.Lots.Add(lot);
             db.SaveChanges();
             ServiceWork.TellAboutStartLot(lot);
             PersonWork.SendMessage(db.Persons.First(), "Auction", "Your lot " + lot.LotName + " is add. Wait for start)", p);
             return(true);
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return(false);
     }
 }
예제 #7
0
 public void TellForPersonAboutStartLot()
 {
     Task.Run(() =>
     {
         using (AuctionContent db = new AuctionContent())
         {
             foreach (Lot elem in db.Lots.Where(elem => elem.TellPersonsAboutStart != null && elem.TimeStart >= DateTime.Now))
             {
                 foreach (Person p in elem.TellPersonsAboutStart)
                 {
                     ClassWork.SendMessage(new Person()
                     {
                         Email = "*****@*****.**", FirstName = "Not ", SecondName = "Empty"
                     }, "Lot is start", "We want to tell you about start lot  " + elem.LotName + "Now", p);
                 }
                 elem.TellPersonsAboutStart = null;
             }
             db.SaveChanges();
         }
     });
 }
예제 #8
0
 public static bool AddPerson(Person person)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             if (db.Persons.FirstOrDefault(elem => elem.Email == person.Email) == null)
             {
                 db.Persons.Add(person);
                 db.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return(false);
     }
 }
예제 #9
0
파일: BLL.cs 프로젝트: Zizaveta/LotsMaster
 public static string Bet(Person p, int lotId, int money)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             db.Persons.Attach(p);
             if (db.Lots.FirstOrDefault(elem => elem.Id == lotId) == null)
             {
                 return("Wrong id of lot");
             }
             if (db.Lots.FirstOrDefault(elem => elem.Id == lotId).TimeFinish < DateTime.Now)
             {
                 return("Lot is finished");
             }
             if (db.Lots.FirstOrDefault(elem => elem.Id == lotId).TimeStart > DateTime.Now)
             {
                 return("Lot is not start");
             }
             if (LastBet(lotId) != 0 && LastBet(lotId) >= money)
             {
                 return("Small bet");
             }
             LotHistory l = new LotHistory()
             {
                 Persson = p, Money = money, Lot = db.Lots.FirstOrDefault(elem => elem.Id == lotId)
             };
             db.History.Add(l);
             db.Lots.First(elem => elem.Id == lotId).History.Add(l);
             db.SaveChanges();
             return("You make Bet!)");
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return("Something wrong with db");
     }
 }
예제 #10
0
파일: BLL.cs 프로젝트: Zizaveta/LotsMaster
 public static string AddPerson(Person person)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             if (db.Persons.FirstOrDefault(elem => elem.Email == person.Email) != null)
             {
                 return("This email is in db");
             }
             else
             {
                 db.Persons.Add(person);
                 db.SaveChanges();
                 return("Peron add");
             }
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return("Wrong in db");
     }
 }
예제 #11
0
 public static bool Bet(Person p, int lotId, int money)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             if (db.Lots.FirstOrDefault(elem => elem.Id == lotId) == null)
             {
                 return(false);
             }
             if (db.Lots.FirstOrDefault(elem => elem.Id == lotId).History.Last().Money > money)
             {
                 return(false);
             }
             if (db.Lots.FirstOrDefault(elem => elem.Id == lotId).TimeFinish < DateTime.Now)
             {
                 return(false);
             }
             if (db.Lots.FirstOrDefault(elem => elem.Id == lotId).TimeStart > DateTime.Now)
             {
                 return(false);
             }
             db.History.Add(new LotHistory()
             {
                 Persson = p, Money = money, Lot = db.Lots.FirstOrDefault(elem => elem.Id == lotId)
             });
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return(false);
     }
 }
예제 #12
0
 public static bool TellMeAboutStartLot(Person person, int lotId)
 {
     try
     {
         using (AuctionContent db = new AuctionContent())
         {
             if (db.Lots.First(elem => elem.Id == lotId).TimeStart <= DateTime.Now)
             {
                 return(false);
             }
             if (db.Lots.First(elem => elem.Id == lotId).TellPersonsAboutStart.Contains(person) == false)
             {
                 db.Lots.First(elem => elem.Id == lotId).TellPersonsAboutStart.Add(person);
                 db.SaveChanges();
             }
             return(true);
         }
     }
     catch (Exception ex)
     {
         Log.Logger(ex.Message);
         return(false);
     }
 }