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