private void SetAssignmnetLetter(Assignment newAssignment) { var letters = "abcdefghijklmnopqrstuvwxyz"; var assignmnetCount = _assignmentService.FindBy(item => item.Number == newAssignment.Number).Count(); newAssignment.ChildLetter = letters[assignmnetCount - 1].ToString(); }
public async Task <ActionResult> Edit(int?id) { var assignmentVm = new AssignmentViewModel(); var user = UserManager.FindByName(User.Identity.Name); if (user != null) { assignmentVm.Name = user.FirstName + " " + user.LastName; } var isAdmin = User.IsInRole("admin"); if (id.HasValue) { var assignment = _assignmentService.AllIncluding(item => item.Invoices, item => item.Invoices.Select(e => e.InvoiceAttachments), item => item.Invoices.Select(e => e.InvoiceStatus), item => item.Invoices.Select(e => e.InvoiceAttachments.Select(a => a.Attachment))) .FirstOrDefault(item => item.Id == id && (isAdmin || item.CustomerId == CustomerId)); Mapper.Map(assignment, assignmentVm); assignmentVm.InvoicesCount = assignment.Invoices.Count; if (!isAdmin) { //load everything in assignment assignmentVm.Invoices = Mapper.Map <List <InvoiceViewModel> >(assignment.Invoices); foreach (var invoice in assignmentVm.Invoices) { invoice.Attachments = assignment.Invoices.Find(item => item.Id == invoice.Id) .InvoiceAttachments.Select(item => item.Attachment) .Select(item => new AttachmentViewModel { Id = item.Id, Name = item.Name, Path = item.Path }).ToList(); } } ViewBag.Title = "Edit Assignment # " + assignmentVm.Number; if (isAdmin) { //get previous overpaid amount var adjustment = _overpaymentService.FindBy( item => item.CustomerId == assignment.CustomerId && item.StatusId == 1).Sum(item => (decimal?)item.Amount); if (adjustment.HasValue && adjustment != 0) { ViewBag.Adjustment = adjustment; } return(View("AdminEditAssignment", assignmentVm)); } } else { assignmentVm.CustomerName = _customerService.Find(CustomerId).CustomerName; var assignmentsForCustomer = _assignmentService.FindBy(item => item.CustomerId == CustomerId); assignmentVm.Number = (assignmentsForCustomer.Any()?assignmentsForCustomer.Max(item => item.Number):0) + 1; assignmentVm.Invoices = new List <InvoiceViewModel>() { new InvoiceViewModel { Id = 0 } }; ViewBag.Title = "Create Assignment"; } if (!isAdmin) { ViewBag.CustomerRate = _customerService.Find(CustomerId).Rate / 100; } return(View(assignmentVm)); }