public string Cancel(int id, int userId)
 {
     Console.WriteLine("MeetupModel.Cancel : START");
     try
     {
         var context     = new SantanderChalengeContext();
         var res         = context.Meetups.SingleOrDefault(x => x.Id == id);
         var permissions = res.UserOrganizer == userId;
         if (permissions)
         {
             res.Canceled = 1;
             context.SaveChanges();
             Console.WriteLine("MeetupModel.Cancel : END");
             return("");
         }
         else
         {
             Console.WriteLine("MeetupModel.Cancel : END");
             return("Permisos insuficientes para realizar esta accion.");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("MeetupModel.Cancel : ERROR : " + ex.Message);
         return(ex.Message);
     }
 }
Exemple #2
0
        public string Create(string userName, string name, string pass, string email, bool admin)
        {
            Console.WriteLine("UsersModel.Create : START");
            try
            {
                SantanderChalengeContext context = new SantanderChalengeContext();
                Users user = new Users()
                {
                    UserName = userName,
                    Name     = name,
                    Pass     = pass,
                    Email    = email,
                    Admin    = admin ? 1 : -1
                };

                context.Users.Add(user);
                context.SaveChanges();
                Console.WriteLine("UsersModel.Create : END");
                return("");
            }
            catch (Exception ex)
            {
                Console.WriteLine("UsersModel.Create : ERROR : " + ex.Message);
                return(ex.Message);
            }
        }
        public string Create(int userOrganizer, string title, DateTime date, int guests)
        {
            Console.WriteLine("MeetupModel.Create : START");
            try
            {
                var context = new SantanderChalengeContext();

                var permissions = context.Users.SingleOrDefault(x => x.Id == userOrganizer).Admin;
                if (permissions == 1)
                {
                    var met = new Meetups();
                    met.UserOrganizer = userOrganizer;
                    met.Date          = date;
                    met.Title         = title;
                    met.Canceled      = -1;
                    met.Guests        = guests;
                    context.Meetups.Add(met);
                    context.SaveChanges();
                    Console.WriteLine("MeetupModel.Create : END");
                    return("");
                }
                else
                {
                    return("Permisos insuficientes para realizar esta accion.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("MeetupModel.Create : ERROR : " + ex.Message);
                return(ex.Message);
            }
        }
 public string Delete(int id, int userId)
 {
     Console.WriteLine("MeetupModel.Delete : START");
     try
     {
         var context     = new SantanderChalengeContext();
         var res         = context.Meetups.SingleOrDefault(x => x.Id == id);
         var permissions = res.UserOrganizer == userId;
         if (permissions)
         {
             context.Remove(context.Meetups.Single(x => x.Id == id));
             context.SaveChanges();
             Console.WriteLine("MeetupModel.Delete : END");
             return("");
         }
         else
         {
             Console.WriteLine("MeetupModel.Cancel : END");
             return("Solo el Organizador puede realizar esta accion.");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("MeetupModel.Delete : ERROR : " + ex.Message);
         return(ex.Message);
     }
 }
 public List <MeetupResponse> GetAll(int userId)
 {
     Console.WriteLine("MeetupModel.GetAll : START");
     try
     {
         var context  = new SantanderChalengeContext();
         var admin    = context.Users.FirstOrDefault(x => x.Id == userId).Admin;
         var response = (from m in context.Meetups
                         join u in context.Users on m.UserOrganizer equals u.Id
                         select new MeetupResponse {
             Meetup = new Meetups {
                 Id = m.Id,
                 UserOrganizer = m.UserOrganizer,
                 Title = m.Title,
                 Date = m.Date,
                 Canceled = m.Canceled,
                 Guests = m.Guests
             },
             Organizer = new Users {
                 Id = u.Id,
                 Name = u.Name,
                 Admin = u.Admin
             },
             BirrasCount = admin == -1 ? -1 : CalculateBirra(m.Date, m.Guests),
             TempDay = GetTemp(m.Date)
         }).ToList();
         Console.WriteLine("MeetupModel.GetAll : END");
         return(response);
     }
     catch (Exception ex)
     {
         Console.WriteLine("MeetupModel.GetAll : ERROR : " + ex.Message);
         return(null);
     }
 }
Exemple #6
0
 public Users Login(string user, string pass)
 {
     Console.WriteLine("UsersModel.Login : START");
     try
     {
         SantanderChalengeContext context = new SantanderChalengeContext();
         Console.WriteLine("UsersModel.Login : END");
         return(context.Users.Where(x => (x.UserName == user) && (x.Pass == pass)).FirstOrDefault());
     }
     catch (Exception ex)
     {
         Console.WriteLine("UsersModel.Login : ERROR : " + ex.Message);
         return(null);
     }
 }
Exemple #7
0
 public string Delete(int id)
 {
     Console.WriteLine("UsersModel.Delete : START");
     try
     {
         SantanderChalengeContext context = new SantanderChalengeContext();
         context.Remove(context.Users.Single(x => x.Id == id));
         context.SaveChanges();
         Console.WriteLine("UsersModel.Delete : END");
         return("");
     }
     catch (Exception ex)
     {
         Console.WriteLine("UsersModel.Delete : ERROR : " + ex.Message);
         return(ex.Message);
     }
 }