public ActionResult Edit(SoaModel model) { try { var invoiceList = Uow.Invoices.GetAll() .Where(i => i.Policy.ClientId == model.ClientId) .Where(i => i.Policy.InsuranceProviderId == model.InsuranceProviderId) .Where(i => i.Status.Name.ToLower() == "unpaid") .Where(i => i.IssueDate < model.IssueDate) .ToList(); var tmpEntity = Uow.Soas.GetById(model.Id); // amount can only be recomputed if unpaid model.StatusName = AttributeProviderSvc.GetSoaStatusNameFromId(model.StatusId); if (model.StatusName.ToLower() == "unpaid") { model.TotalAmountDue = invoiceList.Select(i => i.TotalAmountDue).Sum(); } else { model.TotalAmountDue = tmpEntity.TotalAmountDue; } Uow.Soas.Detach(tmpEntity); var entity = AutoMapper.Mapper.Map <Soa>(model); // EDWIN entity.StartDate = tmpEntity.StartDate; // EDWIN END Uow.Soas.Update(entity); LogEdit(entity); // if SOA is marked as paid, mark corresponding invoices as paid as well if (model.StatusName.ToLower() == "paid") { foreach (var invoice in invoiceList) { invoice.StatusId = AttributeProviderSvc.GetInvoiceStatusIdFromName("paid"); invoice.PaidDate = DateTime.Now; Uow.Invoices.Update(invoice); LogInvoiceEdit(invoice); } } Uow.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { return(RedirectToAction("Index", new { error = "Something went wrong!" })); } }
// GET: Soa public ActionResult Index(string error) { var unpaidStatusId = AttributeProviderSvc.GetInvoiceStatusIdFromName("unpaid"); var list = Uow.Soas.GetAll() .OrderBy(s => s.StatusId) .ProjectTo <SoaModel>(new { invoiceStatus = unpaidStatusId }) .ToList(); foreach (var item in list) { if (item.IsOrganization) { item.ClientName = item.OrganizationName; } } List <ExistingClientsViewModel> clients; clients = Uow.Clients.GetAll() .Where(c => c.Policies.Count() != 0) .ProjectTo <ExistingClientsViewModel>().ToList(); foreach (var item in clients) { if (item.IsOrganization) { item.ClientName = item.OrganizationName; } } List <SoaStatus> statuses; statuses = Uow.SoaStatuses.GetAll().ToList(); var vm = new SoaIndexModel { SoaList = list, HasError = string.IsNullOrEmpty(error) == false, Error = error, Clients = clients.OrderBy(c => c.ClientName).ToList(), Companies = ListProviderSvc.GetInsuranceProviders(), Statuses = statuses }; return(View(vm)); }
public ActionResult Create(InvoiceModel model) { try { if (ModelState.IsValid == false) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } model.StatusId = AttributeProviderSvc.GetInvoiceStatusIdFromName("pending");; var entity = AutoMapper.Mapper.Map <Invoice>(model); Uow.Invoices.Add(entity); Uow.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { LoggingSvc.LogError(ex); return(View()); } }
public ActionResult InvoiceAction(IList <InvoiceActionViewModel> list) { int statusId; if (list == null || list.Count <= 0) { return(RedirectToAction("Index", "Invoice")); } if (list[0].IsApprove) { statusId = AttributeProviderSvc.GetInvoiceStatusIdFromName("approved"); } else { statusId = AttributeProviderSvc.GetInvoiceStatusIdFromName("rejected"); } foreach (var item in list) { if (item.IsSelected) { var entity = Uow.Invoices.GetById(item.InvoiceId); if (entity != null) { entity.StatusId = statusId; Uow.Invoices.Update(entity); } } } Uow.SaveChanges(); return(RedirectToAction("Index", "Invoice")); }