public IActionResult SaveVendor(Dto.Purchasing.Vendor vendorModel) { if (ModelState.IsValid) { var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(vendorModel); var content = new StringContent(serialize); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var response = PostAsync("purchasing/savevendor", content); return(RedirectToAction("Vendors")); } else { ViewBag.Accounts = Models.SelectListItemHelper.Accounts(); ViewBag.TaxGroups = Models.SelectListItemHelper.TaxGroups(); ViewBag.PaymentTerms = Models.SelectListItemHelper.PaymentTerms(); } if (vendorModel.Id == -1) { ViewBag.PageContentHeader = "New Vendor"; } else { ViewBag.PageContentHeader = "Vendor Card"; } return(View("Vendor", vendorModel)); }
public IActionResult Vendors() { IList <Dto.Purchasing.Vendor> vendorsDto = new List <Dto.Purchasing.Vendor>(); try { var vendors = _purchasingService.GetVendors(); foreach (var vendor in vendors) { var vendorDto = new Dto.Purchasing.Vendor() { Id = vendor.Id, No = vendor.No, Name = vendor.Party.Name, Email = vendor.Party.Email, Phone = vendor.Party.Phone, Fax = vendor.Party.Fax, Website = vendor.Party.Website, Balance = vendor.GetBalance(), Contact = vendor.PrimaryContact.FirstName + " " + vendor.PrimaryContact.LastName, TaxGroup = vendor.TaxGroup == null ? string.Empty : vendor.TaxGroup.Description, }; vendorsDto.Add(vendorDto); } return(new ObjectResult(vendorsDto)); } catch (Exception ex) { return(new ObjectResult(ex)); } }
public IActionResult SaveVendor([FromBody] Dto.Purchasing.Vendor vendorDto) { bool isNew = vendorDto.Id == 0; Core.Domain.Purchases.Vendor vendor = null; if (isNew) { vendor = new Core.Domain.Purchases.Vendor(); vendor.Party = new Core.Domain.Party(); vendor.PrimaryContact = new Core.Domain.Contact(); vendor.PrimaryContact.Party = new Core.Domain.Party(); } else { vendor = _purchasingService.GetVendorById(vendorDto.Id); } vendor.No = vendorDto.No; vendor.Party.PartyType = Core.Domain.PartyTypes.Vendor; vendor.Party.Name = vendorDto.Name; vendor.Party.Phone = vendorDto.Phone; vendor.Party.Fax = vendorDto.Fax; vendor.Party.Email = vendorDto.Email; vendor.Party.Website = vendorDto.Website; vendor.AccountsPayableAccountId = vendorDto.AccountsPayableAccountId; vendor.PurchaseAccountId = vendorDto.PurchaseAccountId; vendor.PurchaseDiscountAccountId = vendorDto.PurchaseDiscountAccountId; vendor.TaxGroupId = vendorDto.TaxGroupId; vendor.PaymentTermId = vendorDto.PaymentTermId; if (isNew) { _purchasingService.AddVendor(vendor); } else { _purchasingService.UpdateVendor(vendor); } return(Ok()); }
public IActionResult Vendor(int id = -1) { Dto.Purchasing.Vendor vendorModel = null; if (id == -1) { ViewBag.PageContentHeader = "New Vendor"; vendorModel = new Dto.Purchasing.Vendor(); vendorModel.No = new System.Random().Next(1, 99999).ToString(); // TODO: Replace with system generated numbering. } else { ViewBag.PageContentHeader = "Vendor Card"; vendorModel = GetAsync <Dto.Purchasing.Vendor>("purchasing/vendor?id=" + id).GetAwaiter().GetResult(); } ViewBag.Accounts = Models.SelectListItemHelper.Accounts(); ViewBag.TaxGroups = Models.SelectListItemHelper.TaxGroups(); ViewBag.PaymentTerms = Models.SelectListItemHelper.PaymentTerms(); return(View(vendorModel)); }
public IActionResult Vendor(int id) { try { var vendor = _purchasingService.GetVendorById(id); var vendorDto = new Dto.Purchasing.Vendor() { Id = vendor.Id, No = vendor.No, Name = vendor.Party.Name, Email = vendor.Party.Email, Phone = vendor.Party.Phone, Fax = vendor.Party.Fax, Website = vendor.Party.Website, AccountsPayableAccountId = vendor.AccountsPayableAccountId.GetValueOrDefault(), PurchaseAccountId = vendor.PurchaseAccountId.GetValueOrDefault(), PurchaseDiscountAccountId = vendor.PurchaseDiscountAccountId.GetValueOrDefault(), TaxGroupId = vendor.TaxGroupId.GetValueOrDefault(), PaymentTermId = vendor.PaymentTermId.GetValueOrDefault(), }; if (vendor.PrimaryContact != null) { vendorDto.PrimaryContact.FirstName = vendor.PrimaryContact.FirstName; vendorDto.PrimaryContact.LastName = vendor.PrimaryContact.LastName; vendorDto.PrimaryContact.Party.Email = vendor.PrimaryContact.Party.Email; vendorDto.PrimaryContact.Party.Phone = vendor.PrimaryContact.Party.Phone; vendorDto.PrimaryContact.Party.Fax = vendor.PrimaryContact.Party.Fax; vendorDto.PrimaryContact.Party.Website = vendor.PrimaryContact.Party.Website; vendorDto.PrimaryContact.Party.Name = vendor.PrimaryContact.Party.Name; } return(new ObjectResult(vendorDto)); } catch (Exception ex) { return(new BadRequestObjectResult(ex)); } }