public async Task<HttpResponseMessage> UpdateVendor(long id, long orderId, [FromBody]VendorBookDTO order) { var book = await _bookService.GetByIdAsync(orderId); book.Status = order.Status; await _bookService.Update(book); var result = await _bookService.GetOrdersAsync("vendor", id); if (result == null) return Request.CreateResponse(HttpStatusCode.NotFound); else return Request.CreateResponse(HttpStatusCode.OK, result); }
public async Task <HttpResponseMessage> UpdateBook(VendorBookDTO book) { try { await _bookService.Update(book); } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
public async Task CreateAsync(long accountId, VendorBookDTO book) => await _proxy.RefreshCalendarsEvents(accountId, book);
public async Task Update(VendorBookDTO bookDto) { var book = await _unitOfWork.BookRepository.GetByIdAsync(bookDto.Id); var isStatusChanged = !(bookDto.Status == book.Status); book.Status = bookDto.Status; book.IsHidden = bookDto.IsHidden; if (bookDto.DeclinedReason != null) { book.DeclinedReason = bookDto.DeclinedReason; } _unitOfWork.BookRepository.Update(book); //await CheckBooks(book); await _unitOfWork.SaveAsync(); if (isStatusChanged) { /* Send Notification */ var notification = new NotificationDTO(); string performerName = book.Vendor != null ? $"{book.Vendor.Person.Name} {book.Vendor.Person.Surname}" : book.Company.Name; long receiverId = book.Customer.Person.Account.Id; string confirmedBy = $"{book.Customer.Person.Name} {book.Customer.Person.Surname}"; if (book.IsCompanyTask) { receiverId = book.Company.Account.Id; confirmedBy = book.Company.Name; } string newBookStatus = null; switch (book.Status) { case BookStatus.Accepted: VendorBookDTO _event = new VendorBookDTO { Status = bookDto.Status, Customer = bookDto.Customer, Date = bookDto.Date, EndDate = bookDto.EndDate, Description = bookDto.Description, Work = new WorkDTO { Id = bookDto.Work.Id, Icon = bookDto.Work.Icon, Name = bookDto.Work.Name } }; await _notificationService.CreateAsync(receiverId, _event); notification.Title = newBookStatus = "Order accepted"; notification.Description = $"{performerName} accepted your order ({book.Work.Name})."; break; case BookStatus.Finished: notification.Title = newBookStatus = "Work was finished"; notification.Description = $"{performerName} finished {book.Work.Name} and waiting for your confirmation."; break; case BookStatus.Confirmed: receiverId = book.Vendor != null ? book.Vendor.Person.Account.Id : book.Company.Account.Id; notification.Title = "Work confirmed"; notification.Description = $"{book.Work.Name} was confirmed by {confirmedBy}."; break; case BookStatus.Declined: notification.Title = newBookStatus = "Order was declined"; notification.Description = $"{performerName} decline your order ({book.Work.Name})."; break; } notification.Time = DateTime.Now; await _notificationService.CreateAsync(receiverId, notification); /* Send Message */ if (book.Status != BookStatus.Confirmed) // Only for customer events { string msg = EmailTemplate.OrderStatusChanged(book.Work.Name, newBookStatus, book.Customer.Id); string receiverEmail = book.Vendor != null ? book.Vendor.Person.Account.Email : book.Company.Account.Email; _mailService.Send(new EmailMessage { ReceiverEmail = receiverEmail, Subject = "Work status changed", Body = msg, IsHtml = true }); } } }