Esempio n. 1
0
        public bool EditEvent(Event evt, List <Invitation> invitations)
        {
            using (BookReadingContext context = new BookReadingContext())
            {
                var result = (from i in context.Invitations
                              where i.EventId == evt.EventId
                              select i);

                context.Invitations.RemoveRange(result.ToList());


                foreach (var item in invitations)
                {
                    item.EventId = evt.EventId;
                    context.Invitations.Add(item);
                }
                context.SaveChanges();


                context.Entry(evt).State = EntityState.Modified;

                context.SaveChanges();
                return(true);
            }
        }
Esempio n. 2
0
 public void AddComments(Comment comment)
 {
     using (BookReadingContext context = new BookReadingContext())
     {
         context.Comments.Add(comment);
         context.SaveChanges();
     }
 }
Esempio n. 3
0
 public string GetUserEmail(string userName)
 {
     using (BookReadingContext context = new BookReadingContext())
     {
         string userEmail = (from u in context.Users
                             where u.UserName == userName
                             select u.EmailId).ToList().First();
         return(userEmail);
     }
 }
        public IEnumerable <Event> GetMyEvents(string userName)
        {
            using (BookReadingContext db = new BookReadingContext())
            {
                var evt = (from e in db.Events
                           where e.UserId == userName
                           select e).ToList();

                return(evt);
            }
        }
        public void DeleteEvent(int eventId)
        {
            using (BookReadingContext context = new BookReadingContext())
            {
                var result = (from e in context.Events
                              where e.EventId == eventId
                              select e).ToList().First();

                context.Events.Remove(result);
                context.SaveChanges();
            }
        }
 public string[] GetRoles(string userName)
 {
     using (BookReadingContext context = new BookReadingContext())
     {
         var result = (from user in context.Users
                       join role in context.Roles
                       on user.UserName equals role.UserId
                       where user.UserName == userName
                       select role.AssignedRole).ToArray();
         return(result);
     }
 }
Esempio n. 7
0
 public bool IsValid(User user)
 {
     using (BookReadingContext db = new BookReadingContext())
     {
         var query = (from u in db.Users
                      where u.Password == user.Password
                      select u).ToList();
         if (query.Count != 0)
         {
             return(true);
         }
         return(false);
     }
 }
Esempio n. 8
0
 public bool UserExists(User user)
 {
     using (BookReadingContext db = new BookReadingContext())
     {
         var query = (from u in db.Users
                      where u.UserName.Equals(user.UserName, StringComparison.OrdinalIgnoreCase)
                      select u).ToList();
         if (query.Count != 0)
         {
             return(true);
         }
         return(false);
     }
 }
Esempio n. 9
0
        public void AddUser(User user)
        {
            using (BookReadingContext context = new BookReadingContext())
            {
                context.Users.Add(user);
                context.SaveChanges();
                Role role = new Role();
                role.User         = user;
                role.AssignedRole = "User";
                context.Roles.Add(role);


                context.SaveChanges();
            }
        }
Esempio n. 10
0
 public void CreateEvent(Event evt, List <Invitation> invitations)
 {
     using (BookReadingContext context = new BookReadingContext())
     {
         context.Events.Add(evt);
         context.SaveChanges();
         int id = evt.EventId;
         foreach (var item in invitations)
         {
             item.EventId = id;
             context.Invitations.Add(item);
         }
         context.SaveChanges();
     }
 }
Esempio n. 11
0
 public Event GetEvent(int eventId)
 {
     using (BookReadingContext context = new BookReadingContext())
     {
         IEnumerable <Event> events = context.Events;
         Event eventFound           = null;
         var   query = from evt in events
                       where evt.EventId == eventId
                       select evt;
         if (query != null)
         {
             eventFound = query.ToList().First();
         }
         return(eventFound);
     }
 }
        public IEnumerable <Comment> GetComments(int eventId)
        {
            IEnumerable <Comment> comments = null;

            using (BookReadingContext context = new BookReadingContext())
            {
                var query = from c in context.Comments
                            where c.EventId == eventId
                            select c;
                if (query != null)
                {
                    comments = query.ToList();
                }
                return(comments);
            }
        }
Esempio n. 13
0
        public IEnumerable <Event> GetInvitedTo(string userEmail)
        {
            using (BookReadingContext db = new BookReadingContext())
            {
                IEnumerable <Invitation> invitations = db.Invitations;
                IEnumerable <Event>      events      = db.Events;
                IEnumerable <Event>      invitedTo   = null;


                var query = from i in invitations
                            join e in events
                            on i.Email equals userEmail
                            where i.EventId == e.EventId
                            select e;
                if (query != null)
                {
                    invitedTo = query.ToList();
                }

                return(invitedTo);
            }
        }