public ActionResult PastListMenu(int id) { var model = new CreateSpendViewModel() { ConsortiumId = id }; return(View(model)); }
public ActionResult UpdateSpendById(int id) { var spend = this.SpendService.GetSpend(id); var spendClasses = this.SpendClassService.GetAll() .Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Description }); var spendTypes = this.SpendTypeService.GetAll().Where(x => x.Item.Id == spend.Type.Item.Id && x.Consortium.Id == spend.Consortium.Id) .Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Description }); List <Provider> providerList = this.ProviderService.GetAll().ToList(); providerList.Sort((x, y) => string.Compare(x.User.Name, y.User.Name)); var workers = this.WorkerService.GetAll().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.User.Name + " " + x.User.Surname }); var managers = spend.Consortium.Managers.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.User.Name + " " + x.User.Surname }); var viewModel = new CreateSpendViewModel() { Bill = spend.Bill, Description = spend.Description, ManagerId = spend.Bill.Manager != null ? spend.Bill.Manager.Id : 0, ProviderId = spend.Bill.Provider != null ? spend.Bill.Provider.Id : 0, WorkerId = spend.Bill.Worker != null ? spend.Bill.Worker.Id : 0, Id = spend.Id, SpendTypeId = spend.Type.Id, SpendClassId = spend.SpendClass.Id, SpendTypes = new SelectList(spendTypes, "Value", "Text"), SpendClass = new SelectList(spendClasses, "Value", "Text"), Managers = new SelectList(managers, "Value", "Text"), Providers = new SelectList(providerList, "Id", "User.Name"), Workers = new SelectList(workers, "Value", "Text"), ConsortiumId = spend.Consortium.Id, SpendItemId = spend.Type.Item.Id }; return(View("CreateSpend", viewModel)); }
public ActionResult CreateSpend(int consortiumId, int spendItemId, int?taskId = null) { var consortium = this.ConsortiumService.GetConsortium(consortiumId); var spendTypes = this.SpendTypeService.GetAll().Where(x => x.Item.Id == spendItemId && x.Consortium.Id == consortiumId) .Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Description }); var spendClasses = this.SpendClassService.GetAll() .Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Description }); List <Provider> providerList = this.ProviderService.GetAll().ToList(); providerList.Sort((x, y) => string.Compare(x.User.Name, y.User.Name)); var workers = this.WorkerService.GetAll().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.User.Name + " " + x.User.Surname }); var managers = consortium.Managers.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.User.Name + " " + x.User.Surname }); var viewModel = new CreateSpendViewModel() { SpendTypes = new SelectList(spendTypes, "Value", "Text"), SpendClass = new SelectList(spendClasses, "Value", "Text"), Managers = new SelectList(managers, "Value", "Text"), Providers = new SelectList(providerList, "Id", "User.Name"), Workers = new SelectList(workers, "Value", "Text"), ConsortiumId = consortiumId, SpendItemId = spendItemId, TaskId = taskId }; return(View(viewModel)); }
public ActionResult CreateUpdateSpend(CreateSpendViewModel spend) { var nbill = new BillRequest() { Amount = spend.Bill.Amount, CreationDate = DateTime.Now, Number = spend.Bill.Number, ClientNumber = spend.Bill.ClientNumber, ExpirationDate = spend.Bill.ExpirationDate, NextExpirationDate = spend.Bill.NextExpirationDate, ManagerId = spend.ManagerId, ProviderId = spend.ProviderId, WorkerId = spend.WorkerId, Id = spend.Bill.Id }; var nspend = new SpendRequest() { Description = spend.Description, PaymentDate = DateTime.Now, SpendTypeId = spend.SpendTypeId, SpendClassId = spend.SpendClassId, ConsortiumId = spend.ConsortiumId, TaskId = spend.TaskId, Id = spend.Id }; try { var result = false; Entidad entity = new Entidad() { Id = nbill.Id }; if (nbill.Id == 0) { entity = this.BillService.CreateBill(nbill); result = entity.Id != 0; } else { result = this.BillService.UpdateBill(nbill); } if (result) { if (nspend.Id == 0) { nspend.BillId = entity.Id; result = this.SpendService.CreateSpend(nspend); } else { nspend.BillId = entity.Id; result = this.SpendService.UpdateSpend(nspend); } if (result) { return(Redirect(string.Format("/Spend/Index?Id={0}", spend.ConsortiumId))); } else { return(View("../Shared/Error")); } } else { return(View("../Shared/Error")); } } catch (Exception ex) { return(View("../Shared/Error")); } }