Esempio n. 1
0
        public StrongJsonResult <UserViewModel> LinkUserToUserByEmail(int?fromUserId, string toEmail)
        {
            using (var db = new MyCalendarDbContext())
            {
                var fromUser = db.Users.FirstOrDefault(u => u.UserId == fromUserId);
                if (fromUser != null)
                {
                    var toUser = db.Users.FirstOrDefault(u => u.Email == toEmail && u.UserId != fromUser.UserId);
                    if (toUser != null)
                    {
                        var link = db.UserLinks.FirstOrDefault(l => l.FromUserId == fromUserId &&
                                                               l.ToUserId == toUser.UserId);
                        if (link == null)
                        {
                            link = new UserLink(fromUserId, toUser.UserId);
                            db.UserLinks.Add(link);
                            db.SaveChanges();
                            return(StrongJsonResult.From(new UserViewModel(toUser, toUser.Events)));
                        }
                    }
                }

                return(null);
            }
        }
Esempio n. 2
0
 public StrongJsonResult <int?> RemoveEvent(int?eventId)
 {
     using (var db = new MyCalendarDbContext())
     {
         var evnt = db.Events.FirstOrDefault(e => e.EventId == eventId);
         db.Events.Remove(evnt);
         db.SaveChanges();
         return(StrongJsonResult.From(eventId));
     }
 }
Esempio n. 3
0
 public StrongJsonResult <EventViewModel> AddEvent(EventViewModel model)
 {
     using (var db = new MyCalendarDbContext())
     {
         var evnt = new Event();
         model.WriteTo(evnt);
         db.Events.Add(evnt);
         db.SaveChanges();
         return(StrongJsonResult.From(new EventViewModel(evnt)));
     }
 }
Esempio n. 4
0
        public StrongJsonResult <int?> UpdateUser(UserDetailsModel userModel)
        {
            using (var db = new MyCalendarDbContext())
            {
                var user = db.Users.FirstOrDefault(u => u.UserId == userModel.UserId);
                if (user != null)
                {
                    userModel.WriteTo(user);
                    db.SaveChanges();
                }

                return(StrongJsonResult.From(user?.UserId));
            }
        }
Esempio n. 5
0
        public StrongJsonResult <int?> UnlinkUserFromUser(int?fromUserId, int?toUserId)
        {
            using (var db = new MyCalendarDbContext())
            {
                var link = db.UserLinks.FirstOrDefault(l => l.FromUserId == fromUserId &&
                                                       l.ToUserId == toUserId);
                if (link != null)
                {
                    db.UserLinks.Remove(link);
                    db.SaveChanges();
                    return(StrongJsonResult.From(link.UserLinkId));
                }

                return(null);
            }
        }
Esempio n. 6
0
        public StrongJsonResult <int?> Register(RegisterModel model)
        {
            using (var db = new MyCalendarDbContext())
            {
                var user = new User
                {
                    Name     = model.Name,
                    Email    = model.Email,
                    Password = model.Password
                };

                db.Users.Add(user);
                db.SaveChanges();

                return(StrongJsonResult.From(user.UserId));
            }
        }