public object Approve(ProjectRequest request) { var currentRequest = uow.RequestRepository.Get(r => r.id == request.id, includeProperties: "CreatedBy, Status,Subject, Course,Comments").FirstOrDefault(); if (currentRequest != null) { if (request.Subject != null && request.Subject.id <= 0) { //Create new subject currentRequest.Subject = request.Subject; currentRequest.Subject.createdById = request.createdById; currentRequest.Subject.dateCreated = DateTime.UtcNow; currentRequest.Subject.approvedById = CurrentUser.id; currentRequest.Subject.dateApproved = DateTime.UtcNow; currentRequest.Subject.Courses = new List <Course>(); currentRequest.Subject.Courses.Add(uow.CourseRepository.GetByID(request.courseId)); } RequestComment comment = null; if (request.Comments != null && request.Comments.Count > 0) { comment = new RequestComment { text = request.Comments[0].text }; comment.createdById = CurrentUser.id; comment.dateCreated = DateTime.UtcNow; currentRequest.Comments.Add(comment); } currentRequest.statusId = RequestStatus.SubjectApproved; currentRequest.approvedById = CurrentUser.id; currentRequest.dateApproved = DateTime.UtcNow; var log = new RequestLog(); log.Description = $"Tema {GetSubjectName(currentRequest)} odobrena."; log.Comment = comment; log.createdById = CurrentUser.id; log.dateCreated = DateTime.UtcNow; log.requestId = currentRequest.id; log.requestStatusId = currentRequest.statusId; log.requestChanged = true; uow.RequestLogRepository.Insert(log); uow.Save(); uow.RequestRepository.LoadReference(currentRequest, "Subject"); uow.RequestRepository.LoadReference(currentRequest, "Status"); SendMailForRequest(currentRequest, $"Vaša tema {GetSubjectName(currentRequest)} za predmet {currentRequest.Course?.name} je odobrena", request.Comments?.Count > 0 ? "Napomena: " + request.Comments[0].text : "", toUser: true, toAdmin: false); return(new { request = GetUIObject(currentRequest), log = log }); } return(null); }
protected override async Task HandleCore(AddRequestCommentCommand message) { var comment = new RequestComment { Comment = message.RequestComment, CreatedUtcDate = DateTime.UtcNow, RequestId = message.RequestId, UserId = message.UserId }; _context.RequestComments.Add(comment); await _context.SaveChangesAsync(); }
public async Task <RequestComment> Create(CreateRequestCommentsModel model) { var requestComment = new RequestComment { Comment = model.Comment.Trim(), ServiceProviderID = model.ServiceProviderID, RequestID = model.RequestID }; _uow.Add(requestComment); await _uow.CommitAsync(); return(requestComment); }
private dynamic GetLogRowFromComment(RequestComment c) { return(new { Comment = c != null?GetCommentUIObject(c) : null, CreatedBy = new { c.CreatedBy?.id, c.CreatedBy?.name, c.CreatedBy?.surname }, createdById = c.createdById, dateCreated = Utilities.GetUserTime(c.dateCreated), Description = c.text, Request = GetUIObject(c.Request), requestId = c.requestId, requestChanged = false }); }
private RequestComment GetChilds(CommentaryModel a) { var b = new RequestComment { Id = a.Id, Text = a.Text }; if (a.Answers != null && a.Answers.Any()) { b.Child = a.Answers.Select(x => GetChilds(x)).ToList(); } return(b); }
public int Save(RequestCommentModel model) { RequestComment _requestComment = new RequestComment(model); if (model.Id != null && model.Id != 0) { _RequestComment.Update(_requestComment); } else { // _requestApprove.CreatedDate = System.DateTime.Now; _requestComment = _RequestComment.Insert(_requestComment); } return(_requestComment.Id); }
public static object GetCommentUIObject(RequestComment c, bool includeRequest = false) { return(new { c.text, dateCreated = Utilities.GetUserTime(c.dateCreated), c.createdById, c.requestId, c.statusChange, request = includeRequest ? GetUIObject(c.Request, false) : null, createdBy = c.CreatedBy != null ? new { c.CreatedBy.name, c.CreatedBy.surname } : null, files = c.Files?.Select(f => new { f.id, f.commentId, f.name }) }); }
public async Task <List <Comment> > Handle(RequestComment request, CancellationToken cancellationToken) { return(await _clientWrapper.GetAsync <List <Comment> >(string.Format(_configuration.GetSection("Urls:Comments").Value, request.id))); }
public object CreateComment(RequestComment comment) { var request = uow.RequestRepository.Get(r => r.id == comment.requestId, includeProperties: "Comments, CreatedBy, Subject, Course,Status").FirstOrDefault(); if (request != null) { var oldStatus = request.Status.name; //file handling if (comment.Files != null && comment.Files.Count > 0) { foreach (var f in comment.Files) { f.data = Utilities.GetTempFile(f.file_id); } long currentTotalFileSize; if (!CheckQuota(request.createdById, comment.Files, out currentTotalFileSize)) { return new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent($"Veličina datoteka premašuje vašu kvotu od {Properties.Settings.Default.UploadLimit}. Dosadašnja veličina: {currentTotalFileSize * 1.0 / 1e6:N2} MB. Veličina uploadanih datoteka: {comment.Files.Sum(f => f.data.Length) * 1.0 / 1e6:N2} MB") } } ; } comment.createdById = CurrentUser.id; comment.dateCreated = DateTime.UtcNow; request.Comments.Add(comment); uow.Save(); var workflows = uow.WorkflowRepository.Get().ToList(); RequestLog log = null; if (comment.statusChange == true) { var newStatusId = workflows .FirstOrDefault(w => w.courseId == request.courseId && w.statusId == request.statusId) ?.nextStatusId; if (newStatusId != null) { request.statusId = newStatusId.Value; } uow.Save(); uow.RequestRepository.LoadReference(request, "Status"); log = new RequestLog { commentId = comment.id, createdById = CurrentUser.id, dateCreated = DateTime.UtcNow, requestId = request.id, requestStatusId = request.statusId, Description = $"Status promijenjen iz {oldStatus} u {request.Status.name}. " }; log.requestChanged = comment.statusChange == true; uow.RequestLogRepository.Insert(log); uow.Save(); log.Comment = comment; log.CreatedBy = CurrentUser; } var statusChanged = comment.statusChange == true; comment.Request = request; comment.CreatedBy = CurrentUser; var subject = $"{GetSubjectName(request)} ({request.Course?.name})"; var user = $"{(CurrentUser.IsAdmin ? " administrator" : $" korisnik {CurrentUser.name} {CurrentUser.surname}")}"; SendMailForRequest(request, !statusChanged ? $"Novi komentar u temi {subject}" : $"Promjena statusa teme {subject}", !statusChanged ? $"Za temu {subject} je {user} ostavio novi komentar. <br>Tekst: {comment.text}" : $"Za temu {subject} je {user} promijenio status iz {oldStatus} u {request.Status.name}. <br/>Komentar: {comment.text}" , !CurrentUser.IsAdmin, CurrentUser.IsAdmin, comment.Files); return(statusChanged ? GetLogUIObject(log) : GetLogRowFromComment(comment)); } return(null); }
public object SetStatus(int requestId, int statusId, [FromBody] RequestComment comment) { var request = uow.RequestRepository.Get(r => r.id == requestId, includeProperties: "Status,Subject, Course,Comments, CreatedBy").FirstOrDefault(); var oldStatus = request.Status?.name; if (request != null) { request.statusId = statusId; if (statusId == RequestStatus.SubjectApproved) { request.approvedById = CurrentUser.id; request.dateApproved = DateTime.UtcNow; } if (comment != null) { comment.createdById = CurrentUser.id; comment.dateCreated = DateTime.UtcNow; request.Comments.Add(comment); } uow.Save(); uow.RequestRepository.LoadReference(request, "Status"); var log = new RequestLog(); log.Description = $"Status promijenjen iz {oldStatus} u {request.Status.name}"; log.createdById = CurrentUser.id; log.dateCreated = DateTime.UtcNow; log.requestChanged = true; log.requestId = requestId; log.requestStatusId = statusId; log.commentId = comment?.id; uow.RequestLogRepository.Insert(log); uow.Save(); log.Comment = comment; log.CreatedBy = CurrentUser; if (statusId == RequestStatus.RequestCancelled) { SendMailForRequest(request, $"Prijava poništena - {CurrentUser.surname} {CurrentUser.name}. Naziv teme: {GetSubjectName(request)}"); } else if (statusId == RequestStatus.RequestReinstated) { SendMailForRequest(request, $"Prijava ponovno aktivirana - {CurrentUser.surname} {CurrentUser.name}. Naziv teme: {GetSubjectName(request)}"); } else if (statusId == RequestStatus.SubjectApproved) { SendMailForRequest(request, $"Vaša tema {GetSubjectName(request)} za predmet {request.Course?.name} je odobrena", comment != null ? "Napomena: " + comment.text : "", toUser: true, toAdmin: false); } else if (statusId == RequestStatus.SubjectRejected) { SendMailForRequest(request, $"Vaša tema {GetSubjectName(request)} za predmet {request.Course?.name} je odbijena", comment != null ? "Napomena: " + comment.text : "", toUser: true, toAdmin: false); } else if (statusId == RequestStatus.DatabaseApproved) { SendMailForRequest(request, $"Baza podataka za vašu temu {GetSubjectName(request)} za predmet {request.Course?.name} je odobrena", comment != null ? "Napomena: " + comment.text : "", toUser: true, toAdmin: false); } else if (statusId == RequestStatus.CodeApprovedPendingExam) { SendMailForRequest(request, $"Kod za vašu temu {GetSubjectName(request)} za predmet {request.Course?.name} je odobren. Projekt je sada u statusu čekanja obrane. Prijavite se na portal i ako ima otvorenih rokova, prijavite se za obranu.", comment != null ? "Napomena: " + comment.text : "", toUser: true, toAdmin: false); } return(new { request = GetUIObject(request), comment = comment != null?GetCommentUIObject(comment) : null, log = log }); } return(null); }
public object UpdateRequest(ProjectRequest request) { if (request.subjectId != null) { request.subjectText = null; } if (request.subjectId == null && string.IsNullOrEmpty(request.subjectText)) { return new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Tema mora biti upisana.") } } ; var currentRequest = uow.RequestRepository.Get(r => r.id == request.id, includeProperties: "Subject, Course, Status,Comments,CreatedBy").FirstOrDefault(); var subjectChanged = request.subjectId != currentRequest.subjectId || (currentRequest.subjectId == null && request.subjectText != currentRequest.subjectText); var dateDueChanged = request.dateDue?.Date != currentRequest.dateDue?.Date; var statusChanged = request.statusId != currentRequest.statusId; var previousSubjectName = GetSubjectName(currentRequest); var previousDateDue = currentRequest.dateDue; var previousStatus = currentRequest.Status.name; currentRequest.subjectText = request.subjectText; currentRequest.subjectId = request.subjectId; currentRequest.dateDue = request.dateDue; currentRequest.statusId = request.statusId; currentRequest.courseId = request.courseId; currentRequest.comment = request.comment; RequestComment newComment = null; if (request.Comments != null && request.Comments.Count > 0) { newComment = request.Comments[0]; newComment.createdById = CurrentUser.id; newComment.dateCreated = DateTime.UtcNow; currentRequest.Comments.Add(newComment); } uow.Save(); uow.RequestRepository.LoadReference(currentRequest, "Subject"); uow.RequestRepository.LoadReference(currentRequest, "Course"); uow.RequestRepository.LoadReference(currentRequest, "Status"); var change = "Prijava promijenjena."; if (subjectChanged) { change += $" Stara tema: {previousSubjectName} Nova tema: {GetSubjectName(currentRequest)}."; } if (dateDueChanged) { change += $" Stari datum isteka: {Utilities.GetUserTime(previousDateDue)?.ToShortDateString()} Novi datum isteka: {Utilities.GetUserTime(currentRequest.dateDue)?.ToShortDateString()}"; } if (statusChanged) { change += $" Stari status: {previousStatus} Novi status: {currentRequest.Status.name}"; } var newCommentText = (newComment != null ? $"Komentar: {newComment.text}" : string.Empty); var log = new RequestLog { commentId = newComment?.id, createdById = CurrentUser.id, dateCreated = DateTime.UtcNow, Description = change, requestId = currentRequest.id, requestStatusId = currentRequest.statusId, requestChanged = subjectChanged || dateDueChanged || statusChanged }; uow.RequestLogRepository.Insert(log); uow.Save(); log.Comment = newComment; log.CreatedBy = CurrentUser; if (subjectChanged && !CurrentUser.IsAdmin) { SendMailForRequest(request, $"Prijava promijenjena: {CurrentUser.surname} {CurrentUser.name} - {currentRequest.Course?.name}", $"Stara tema: {previousSubjectName} Nova tema: {GetSubjectName(currentRequest)}<br>{newCommentText}"); } if (dateDueChanged && CurrentUser.IsAdmin) { SendMailForRequest(request, "Datum isteka teme promijenjen", $"Datum isteka za vašu temu {GetSubjectName(currentRequest)} za predmet #course# je promijenjen na {currentRequest.dateDue?.ToString("d")}<br>{newCommentText} ", false, true); } if (statusChanged && CurrentUser.IsAdmin) { SendMailForRequest(request, "Status teme promijenjen", $"Status vaše teme {GetSubjectName(currentRequest)} za predmet #course# je promijenjen na {currentRequest.Status?.name} <br>{newCommentText}", false, true); } return(new { request = GetUIObject(currentRequest), log = log }); }