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 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); } }
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 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); } }