public ActionResult Details(int?ID) { if (ID == null) { return(NotFound()); } var ServiceOrder = _context.ServiceOrders .Include(so => so.Creator) .Include(so => so.Client) .ToList() .Find(so => so.Id == ID); var comments = _context.Comment.Where(c => c.ServiceOrder.Id == ID) .Include(c => c.Commentor); var billedCosts = _context.BillableTime.Where(bt => bt.ServiceOrder == ServiceOrder).ToList(); var settings = _context.SiteSettings.First(); double total = 0; foreach (var cost in billedCosts) { total += Math.Round(((double)cost.Cost), 2); } ServiceOrderCommentsViewModel ServiceOrderComments = new ServiceOrderCommentsViewModel { ServiceOrder = ServiceOrder, Comments = comments.ToList(), BillableCost = total }; return(View(ServiceOrderComments)); }
public IActionResult CommentCreate(int?ID) { if (ID == null) { return(NotFound()); } var ServiceOrder = _context.ServiceOrders.Find(ID); ServiceOrderCommentsViewModel ServiceOrderComments = new ServiceOrderCommentsViewModel { ServiceOrder = ServiceOrder }; return(View(ServiceOrderComments)); }
public async Task <IActionResult> CreateComment(ServiceOrderCommentsViewModel c, int id) { var user = await _userManager.GetUserAsync(User); var ServiceOrder = _context.ServiceOrders.Find(id); Comment Comment = new Comment { Commentor = user, Date = DateTime.Now, Content = c.Comment.Content, ServiceOrder = ServiceOrder }; _context.Add(Comment); _context.SaveChanges(); return(RedirectToAction("Index")); }