예제 #1
0
        public void AddUserToBlackList(int Id, int temp, int role)
        {
            var user = work.Users.FirstOrDefault(u => u.Id == Id);

            user.InBlackList = temp != 0;
            user.RoleId      = role;
            work.Users.AddOrUpdate(user);
            work.SaveChanges();
        }
예제 #2
0
 public bool UpdateUserOrder(MenuForUserDTO model, int userId)
 {
     using (var work = new PechkaContext())
     {
         var orderForUpdate = work.Orders.FirstOrDefault(u => u.MenuId == model.MenuId && u.UserId == userId);
         orderForUpdate.WithFirst    = model.OrderWithFirst != 0;
         orderForUpdate.WithoutFirst = model.OrderWithoutFirst != 0;
         work.Orders.AddOrUpdate(orderForUpdate);
         work.SaveChanges();
         return(true);
     }
 }
예제 #3
0
        public int?ChangeScoreByUserId(int userId, decimal newMoney)
        {
            var newScore = newMoney.ToScore(userId);

            using (PechkaContext work = new PechkaContext())
            {
                work.Scores.Add(newScore);
                work.SaveChanges();
                var temp = work.Scores.Where(u => u.UserId == userId).ToArray();
                return(temp[temp.Length - 1].Id);
            }
        }
예제 #4
0
 public bool SaveNewUser(RegistrationModel user)
 {
     if (IsEmailUnique(user.Email))
     {
         //try
         // {
         var userToadd = user.ToUser();
         work.Users.Add(userToadd);
         work.SaveChanges();
         var castedUSer = work.Users.FirstOrDefault(u => u.Email == userToadd.Email);
         if (castedUSer != null)
         {
             Score newScore = new Score();
             newScore.Id     = castedUSer.Id;
             newScore.Date   = DateTime.Now;
             newScore.Money  = 0;
             newScore.UserId = castedUSer.Id;
             work.Scores.Add(newScore);
             work.SaveChanges();
             var makeSh = work.Scores.FirstOrDefault(u => u.UserId == castedUSer.Id);
             castedUSer.ScoreId = makeSh.Id;
             work.Users.AddOrUpdate(castedUSer);
             work.SaveChanges();
         }
         return(true);
         // }
         //catch
         // {
         //return false;
         //}
     }
     return(false);
 }
예제 #5
0
 public bool AddNewOrder(MenuForUserDTO model, int userId)
 {
     using (var work = new PechkaContext())
     {
         var orderToAdd = new Order();
         orderToAdd.UserId       = userId;
         orderToAdd.MenuId       = model.MenuId;
         orderToAdd.WithoutFirst = model.OrderWithoutFirst != 0;
         orderToAdd.WithFirst    = model.OrderWithFirst != 0;
         work.Orders.Add(orderToAdd);
         work.SaveChanges();
         return(true);
     }
 }
예제 #6
0
 public bool UpdateMenu(MenuDTO model)
 {
     using (var work = new PechkaContext())
     {
         try
         {
             var thismenu = work.Meny.FirstOrDefault(u => u.Id == model.Id);
             thismenu.IsCompleted = model.ToMenu().IsCompleted;
             work.Meny.AddOrUpdate(thismenu);
             work.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
예제 #7
0
 public bool AddNewMenu(MenuDTO model)
 {
     using (var work = new PechkaContext())
     {
         try
         {
             if (work.Meny.FirstOrDefault(u => u.Date == model.Date) == null)
             {
                 work.Meny.Add(model.ToMenu());
                 work.SaveChanges();
                 return(true);
             }
             return(false);
         }
         catch
         {
             return(false);
         }
     }
 }
예제 #8
0
        public bool AddNewReview(int userId, int menuId, string body)
        {
            var reviewToAdd = new Review();

            reviewToAdd.UserId = userId;
            reviewToAdd.MenuId = menuId;
            reviewToAdd.Body   = body;
            using (var work = new PechkaContext())
            {
                try
                {
                    work.Reviews.Add(reviewToAdd);
                    work.SaveChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }