public async Task <ExcecutorDTO> AddExcecutor(ExcecutorDTO user) { var task = await taskRepo.FindByIdAsync(user.TaskId); TaskHistory history = new TaskHistory(); history.DateUpdated = DateTime.Now; history.UpdatedByUser = task.Customer; history.StartTaskStatus = await statusRepo.FindByIdAsync((int)task.TaskStatusId); task.ExecutorId = user.ExcecutorId; task.UpdatedById = task.CustomerId; task.DateUpdated = DateTime.Now; var status = (await statusRepo.GetWithIncludeAsync(s => s.Type == "In progress")).FirstOrDefault(); task.TaskStatusId = status.Id; history.FinalTaskStatus = await statusRepo.FindByIdAsync(status.Id); await taskRepo.UpdateAsync(task); await historyRepo.CreateAsync(history); return(user); }
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 <IEnumerable <CommentDTO> > AddComment(CommentDTO comment) { comment.Date = DateTime.Now.ToString(); comment.UserName = (await userRepo.FindByIdAsync(comment.UserId)).Name; var myComment = mapper.Map <CommentDTO, Comment>(comment); await commentRepo.CreateAsync(myComment); var result = await GetComments(comment.TaskId); return(result); }
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 <TaskPageDTO> AddTask(TaskPageDTO task) { var result = mapper.Map <TaskPageDTO, FreelanceLand.Models.Task>(task); result.TaskCategoryId = (await categoryRepo.GetWithIncludeAsync(c => c.Type == task.TaskCategory)) .FirstOrDefault().Id; result.DateCreate = DateTime.Now; result.DateUpdated = DateTime.Now; var status = (await statusRepo.GetWithIncludeAsync(s => s.Type == "To do")).FirstOrDefault(); result.TaskStatusId = status.Id; result.UpdatedById = task.CustomerId; result.DateUpdated = DateTime.Now; await taskRepo.CreateAsync(result); return(task); }
public async Task <Ratings> RateUser(int UserId, int RateByUser, int Mark, int UserStatusId) { var rating = new Ratings(); rating.UserId = UserId; rating.RateByUser = RateByUser; rating.Mark = Mark; rating.UserStatusId = UserStatusId; await ratingRepo.CreateAsync(rating); var countUsers = (await ratingRepo.GetWithIncludeAsync(x => x.UserId == UserId)).Count(); var rat = (await ratingRepo.GetWithIncludeAsync(x => x.UserId == UserId)).Sum(y => y.Mark) / countUsers; User user = await userRepo.FindByIdAsync(UserId); user.Rating = (int)rat; await userRepo.UpdateAsync(user); return(rating); }
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 System.Threading.Tasks.Task AddChatRoomAsync(ChatRoom chatRoom) { await chatRoomRepo.CreateAsync(chatRoom); }