public IActionResult AdminPage() { if (this.t) { t = false; return(View(this.AdminPageModel)); } AdminPageModel adminPageModel = new AdminPageModel(); List <System.Security.Claims.Claim> c = User.Claims.Where(x => x.Type.Contains("mail")).ToList(); string email = c[0].Value; int adminId = context.GetUserId(email); User admin = context.Users.Where(x => x.Id == adminId).ToList()[0]; if (admin.Role != 1) { adminPageModel.IsValid = false; return(View(adminPageModel)); } adminPageModel.IsValid = true; adminPageModel.AdminId = adminId; adminPageModel.Users = GetActiveUsers(adminId); return(View(adminPageModel)); }
public IActionResult EditGroup(int id) { List <System.Security.Claims.Claim> c = User.Claims.Where(x => x.Type.Contains("mail")).ToList(); string email = c[0].Value; int Uid = context.GetUserId(email); Group group = context.Groups.FirstOrDefault(g => g.OwnerId == Uid && g.Id == id); if (group == null) { throw new ArgumentException(); } group.Members = context.GroupMembers.Where(gm => gm.GroupId == group.Id).ToList(); HashSet <string> emails = new HashSet <string>(); foreach (var gm in group.Members) { emails.Add(context.GetUserEmail(gm.UserId)); } EditGroupModel model = new EditGroupModel(); model.OldGroupId = id; model.GroupName = group.GroupName; StringBuilder stringBuilder = new StringBuilder(); foreach (string s in emails) { stringBuilder.Append(s); stringBuilder.Append(";"); } //oldAdress = set; model.Emails = stringBuilder.ToString(); model.Addresses = new HashSet <string>(); return(View(model)); }
public ActionResult Send([FromBody] NewMessageModel message) { List <System.Security.Claims.Claim> c = User.Claims.Where(x => x.Type.Contains("mail")).ToList(); string email = c[0].Value; int id = context.GetUserId(email); System.ComponentModel.DataAnnotations.ValidationResult result = message.Validate(context, id, email); if (result != System.ComponentModel.DataAnnotations.ValidationResult.Success) { return(Json(new { success = false, msg = result.ErrorMessage })); } SendMessageToServer(message, id, email); return(Json(new { success = true, msg = "Wiadomość została wysłana!" })); }
public IActionResult Inbox() { List <System.Security.Claims.Claim> c = User.Claims.Where(x => x.Type.Contains("mail")).ToList(); string email = c[0].Value; int id = context.GetUserId(email); List <InboxMessage> inboxMessages = new List <InboxMessage>(); InboxViewModel inboxViewModel = new InboxViewModel(); List <string> dates = new List <string>(); List <MessageReceiver> messageReceivers = context.MessageReceivers.Where(x => x.UserId == id).ToList(); foreach (var mr in messageReceivers) { int senderId = context.Messages.Where(x => x.Id == mr.MessageId).ToList()[0].SenderId; User sender = context.Users.Where(x => x.Id == senderId).ToList()[0]; InboxMessage inboxMessage = GetMessageModel(mr, sender); inboxMessages.Add(inboxMessage); if (!dates.Contains(inboxMessage.DateDay)) { dates.Add(inboxMessage.DateDay); } } dates.Reverse(); inboxMessages.Sort((m1, m2) => m1.Date.CompareTo(m2.Date)); inboxMessages.Reverse(); inboxViewModel.inboxMessages = inboxMessages; inboxViewModel.dates = dates; return(View(inboxViewModel)); }