public async Task <string> CreateUserImage(ImageDTO Image) { Image im = (await imageRepo.GetAsync((el) => el.UserId == Image.UserId)).FirstOrDefault(); if (im != null) { await imageRepo.RemoveAsync(im); } if (Image == null) { return("empty"); } ; byte[] fileBytes = null; using (var fs1 = Image.Image.OpenReadStream()) using (var memoryStream = new MemoryStream()) { await fs1.CopyToAsync(memoryStream); fileBytes = memoryStream.ToArray(); } Image image = new Image(); image.UserId = Image.UserId; image.FileName = Image.FileName; image.Picture = fileBytes; await imageRepo.CreateAsync(image); return("done"); }
public async Task <UserAccountDTO> CreateUser(string email, string login, string password, string requestURL) { if (await GetUserByLogin(login) == null) { string passwordHash = BCrypt.Net.BCrypt.HashPassword(password); User user = new User(); user.Name = ""; user.Sur_Name = ""; user.Birth_Date = new DateTime(); user.Phone_Number = "+380-*"; user.Email = email; user.Login = login; user.Password = passwordHash; user.EmailConfirmed = false; user.ConfirmCode = Guid.NewGuid().ToString(); user.UserRoleId = (await rolesRepo.GetAsync(r => r.Type == "User")).FirstOrDefault().Id; await userRepo.CreateAsync(user); string MessagesRegistr = $"<h2>Dear user</h2><h3>Your registration request was successful approve</h3><a href='{requestURL}/Account/confirmEmail?confirmCode={user.ConfirmCode}'>Confirm registration </a>"; _emailService.SendEmailAsync(user.Email, "Administration", MessagesRegistr); var dto = _mapper.Map <User, UserAccountDTO>(user); return(dto); } return(null); }
public async Task <User> GetUserById(int id) { var user = (await userRepo.GetAsync(u => u.Id == id)).FirstOrDefault(); if (user == null) { return(null); } return(user); }
public async System.Threading.Tasks.Task <ActionResult <IEnumerable <ChatRoom> > > GetChatRoomsAsync(int id) { ChatRoom chatRoom = (await chatRoomRepo.GetAsync(ch => (ch.Id == id))).FirstOrDefault(); ChatRoomInfoDTO dto = new ChatRoomInfoDTO(); dto.Name = chatRoom.Name; dto.Id = chatRoom.Id; dto.FirstUserLogin = (await userRepo.GetAsync(u => u.Id == chatRoom.CreatorId)).FirstOrDefault().Login; dto.SecondUserLogin = (await userRepo.GetAsync(u => u.Id == chatRoom.SecondUserId)).FirstOrDefault().Login; return(Ok(dto)); }
public async Task <IEnumerable <NotificationDTO> > GetNotificationsAsync(int userId) { var notifications = await notiRepo.GetAsync(x => x.UserId == userId); if (notifications == null) { return(null); } var dtos = _mapper.Map <IEnumerable <Notification>, IEnumerable <NotificationDTO> >(notifications); return(dtos); }
public async Task <IEnumerable <TaskCategoryDTO> > GetCategories() { IEnumerable <TaskCategoryDTO> result = mapper.Map <IEnumerable <TaskCategory>, IEnumerable <TaskCategoryDTO> > (await categoryRepo.GetAsync()); return(result); }
public async Task <ActionResult> DeleteOrg(string Id) { EFGenericRepository <Org> Orgs = new EFGenericRepository <Org>(DbContext); Org org = await Orgs.GetAsync(x => x.Id == Id); try { DbContext.Orgs.Attach(org); Org o = DbContext.Orgs.Remove(org); await DbContext.SaveChangesAsync(); if (Request.IsAjaxRequest()) { return(Content("success")); } else { return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", "Ошибка обновления общества " + ex.Message); //Response.StatusCode = (int)HttpStatusCode.BadRequest; return(View(Request.IsAjaxRequest() ? "_DeletePartial" : "Delete", org)); } }
public async Task <ActionResult> DeleteOrgUsers(string Id) { EFGenericRepository <OrgUsers> query = new EFGenericRepository <OrgUsers>(DbContext); OrgUsers model = await query.GetAsync(x => x.Id == Id); try { DbContext.OrgUsers.Attach(model); OrgUsers o = DbContext.OrgUsers.Remove(model); await DbContext.SaveChangesAsync(); if (Request.IsAjaxRequest()) { return(Content("success")); } else { return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", "Ошибка обновления общества " + ex.Message); EFGenericRepository <OrgUsersViewModel> queryView = new EFGenericRepository <OrgUsersViewModel>(DbContext); OrgUsersViewModel modelView = await queryView.GetAsync(x => x.Id == Id); return(View(Request.IsAjaxRequest() ? "_DeletePartial" : "Delete", modelView)); } }
public async Task <IEnumerable <TopUserDTO> > GetTop5Users() { //TODO: change select query when rating field will be added to user table var entities = await _users.GetAsync(t => t.Id != 0, 5); var dtos = mapper.Map <IEnumerable <User>, IEnumerable <TopUserDTO> >(entities); return(dtos); }
public async Task <ActionResult> Details(string id) { EFGenericRepository <Org> Orgs = new EFGenericRepository <Org>(DbContext); Org model = await Orgs.GetAsync(x => x.Id == id); if (Request.IsAjaxRequest()) { return(PartialView("_detailsPartial", model)); } return(View(model)); }
public async System.Threading.Tasks.Task <List <ChatRoomWithUserNamesDTO> > GetChatRoomsListAsync(int id) { IEnumerable <ChatRoom> chatRooms = await chatRoomRepo.GetAsync(ch => (ch.CreatorId == id) || (ch.SecondUserId == id)); List <ChatRoomWithUserNamesDTO> dtos = new List <ChatRoomWithUserNamesDTO>(chatRooms.Count()); foreach (ChatRoom ch in chatRooms) { ChatRoomWithUserNamesDTO chR = new ChatRoomWithUserNamesDTO(); chR.Id = ch.Id; chR.Name = ch.Name; chR.FirstUserName = (await userRepo.GetAsync(u => u.Id == ch.CreatorId)).FirstOrDefault().Name; chR.SecondUserName = (await userRepo.GetAsync(u => u.Id == ch.SecondUserId)).FirstOrDefault().Name; chR.FirstUserLogin = (await userRepo.GetAsync(u => u.Id == ch.CreatorId)).FirstOrDefault().Login; chR.SecondUserLogin = (await userRepo.GetAsync(u => u.Id == ch.SecondUserId)).FirstOrDefault().Login; dtos.Add(chR); } return(dtos); }
public async System.Threading.Tasks.Task AddNotification(string message, int?userId) { var user = (await userRepo.GetAsync(x => x.Id == userId)).FirstOrDefault(); if (user != null) { Notification notif = new Notification(); notif.Message = message; notif.DateAndTime = DateTime.Now; notif.UserId = user.Id; await notiRepo.CreateAsync(notif); } }
public async Task <User> UpdateUser(int id, [FromBody] UserInformation value) { var user = await _usersService.GetUserByLogin(value.Login); var role = (await roleRepo.GetAsync(x => x.Id == user.UserRoleId)).FirstOrDefault(); if (value.UserRoleName != null && value.UserRoleName != role.Type) { string msg = $"Your role was changed to {value.UserRoleName}"; await _notificationService.AddNotification(msg, id); await _hubContext.Clients.All.SendAsync("sendMessage", id, msg); } var dtos = await _usersService.UpdateUser(id, value); return(dtos); }
public async Task <List <MessageToUserDTO> > GetMessagesForChatRoomAsync(int chatRoomId) { IEnumerable <Message> messages = await messageRepo.GetAsync(m => m.ChatRoomId == chatRoomId); List <MessageToUserDTO> dtos = new List <MessageToUserDTO>(messages.Count()); foreach (Message msg in messages) { MessageToUserDTO m = new MessageToUserDTO(); m.Content = msg.Content; m.SenderLogin = (await userRepo.GetAsync(u => u.Id == msg.SenderUserId)).FirstOrDefault().Login; m.DateAndTime = msg.DateAndTime.ToLongTimeString(); dtos.Add(m); } return(dtos); }
public async System.Threading.Tasks.Task DeleteTask(int id) { var task = await taskRepo.FindByIdAsync(id); var comment = await commentRepo.GetAsync(c => c.TaskId == task.Id); var history = await historyRepo.GetAsync(h => h.Task.Id == task.Id); foreach (var c in comment) { await commentRepo.RemoveAsync(c); } foreach (var h in history) { await historyRepo.RemoveAsync(h); } await taskRepo.RemoveAsync(task); }
private async Task <ClaimsIdentity> GetIdentity(string username, string password) { User person = (await userRepo.GetAsync(u => u.Login == username)).FirstOrDefault(); string role = (await rolesRepo.GetAsync(r => r.Id == person.UserRoleId)).FirstOrDefault().Type; if (person != null) { var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, person.Login), new Claim(ClaimsIdentity.DefaultRoleClaimType, role) }; ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); return(claimsIdentity); } return(null); }
public async System.Threading.Tasks.Task AddMessageToRoomAsync(int chatRoomId, Message message, int SenderId) { message.SenderUserId = SenderId; message.ChatRoomId = chatRoomId; message.DateAndTime = DateTime.Now; await messageRepo.CreateAsync(message); var userName = (await usersService.GetUserById(SenderId)).Name; string msg = $"You have new message from {userName}"; var chatRoom = (await chatRoomRepo.GetAsync(x => x.Id == message.ChatRoomId)).FirstOrDefault(); int? userId; if (chatRoom.CreatorId == message.SenderUserId) { userId = chatRoom.SecondUserId; } else { userId = chatRoom.CreatorId; } await _hubContext.Clients.All.SendAsync("chatNotification", userId, msg); }
public async Task <Comment> GetComment(int id) { var comment = (await commentRepo.GetAsync(c => c.Id == id)).FirstOrDefault(); return(comment); }
public async System.Threading.Tasks.Task <IEnumerable <ChatRoom> > GetChatRoomsAsync() { IEnumerable <ChatRoom> chatRooms = await chatRoomRepo.GetAsync(); return(chatRooms); }
public async Task <int?> GetCustomerAsync(int id) { var customer = (await taskRepo.GetAsync(x => x.Id == id)).FirstOrDefault().CustomerId; return(customer); }