public SupplierFormView(SupplierFormViewModel viewModel) { DataContext = viewModel; InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; Closed += OnWindowClosed; }
public IActionResult Details(int id) { SupplierFormViewModel viewModel = new SupplierFormViewModel(); Supplier client = _supplierRepository.FindById(id, _employeeLogin.GetEmployee().BusinessId); if (client is SupplierJuridical) { viewModel.SupplierJuridical = (SupplierJuridical)client; } else { viewModel.SupplierPhysical = (SupplierPhysical)client; } foreach (var item in client.Contacts) { if (item.TypeNumber == Models.Enums.TypeNumber.Celular) { viewModel.Celular = item; } if (item.TypeNumber == Models.Enums.TypeNumber.Residencial) { viewModel.Comercial = item; } } viewModel.Address = client.Address; return(View(viewModel)); }
public IActionResult Insert(SupplierFormViewModel supplier) { if (ModelState.IsValid) { if (supplier.SupplierJuridical != null) { supplier.SupplierJuridical.InsertDate = DateTime.Now; supplier.SupplierJuridical.Address.InsertDate = DateTime.Now; foreach (var item in supplier.SupplierJuridical.Contacts) { item.InsertDate = DateTime.Now; } supplier.SupplierJuridical.RegisterEmployeeId = _employeeLogin.GetEmployee().Id; _supplierRepository.Insert(supplier.SupplierJuridical); } else { supplier.SupplierPhysical.InsertDate = DateTime.Now; supplier.SupplierPhysical.Address.InsertDate = DateTime.Now; foreach (var item in supplier.SupplierPhysical.Contacts) { item.InsertDate = DateTime.Now; } supplier.SupplierPhysical.RegisterEmployeeId = _employeeLogin.GetEmployee().Id; _supplierRepository.Insert(supplier.SupplierPhysical); } TempData["MSG_S"] = Message.MSG_S_002; return(Json("Ok")); } return(Json("Error")); }
public IActionResult NewSupplier() { SupplierFormViewModel viewModel = new SupplierFormViewModel { Action = "NewSupplier" }; return(View("FormSupplier", viewModel)); }
public ActionResult New() { var cities = _context.Cities.ToList(); var viewModel = new SupplierFormViewModel { Cities = cities }; return(View("SupplierForm", viewModel)); }
public IActionResult Create(SupplierFormViewModel model) { if (!ModelState.IsValid) { model.Parts = this.GetAllParts(); return(View()); } this.supplierService.Create(model.Name, model.IsImporter, model.SelectedParts); return(RedirectToAction(nameof(All))); }
public ActionResult Edit(int Id) { var supplier = _context.Suppliers.Single(s => s.Id == Id); var viewModel = new SupplierFormViewModel { Supplier = supplier, Cities = _context.Cities.ToList() }; return(View("SupplierForm", viewModel)); }
public IActionResult NewSupplier(SupplierFormViewModel supplier) { if (!ModelState.IsValid) { return(View("FormSupplier", supplier)); } var supplierToAdd = new Supplier(); _mapper.Map(supplier, supplierToAdd); _context.Suppliers.Add(supplierToAdd); _context.SaveChanges(); var routeValue = new RouteValueDictionary(new { action = "Index", controller = "Suppliers" }); return(RedirectToRoute(routeValue)); }
public IActionResult UpdateSupplier(int id, SupplierFormViewModel supplier) { if (!ModelState.IsValid) { return(View("FormSupplier", supplier)); } var supplierToEdit = _context.Suppliers.FirstOrDefault(s => s.ID == id); _mapper.Map(supplier, supplierToEdit); _context.SaveChanges(); var routeValue = new RouteValueDictionary(new { action = "Index", controller = "Suppliers" }); return(RedirectToRoute(routeValue)); }
public IActionResult UpdateSupplier(int id) { var supplier = _context.Suppliers.FirstOrDefault(s => s.ID == id); if (supplier == null) { return(NotFound()); } SupplierFormViewModel viewModel = new SupplierFormViewModel { Action = "UpdateSupplier" }; _mapper.Map(supplier, viewModel); return(View("FormSupplier", viewModel)); }
public IHttpActionResult GetSupplierDetails(int id) { try { //UpdateSupplierDetailsViewModel updateSupplierDetailsViewModel = new UpdateSupplierDetailsViewModel(); SupplierFormViewModel updateSupplierDetailsViewModel = new SupplierFormViewModel(); //SupplierPaymentTypeViewModel supplierPaymentType = new SupplierPaymentTypeViewModel(); Supplier supplier = new Supplier(); supplier = _supplier.GetSupplier(id); if (supplier != null) { updateSupplierDetailsViewModel.supplierPaymentTypes = new SupplierPaymentTypeViewModel(); updateSupplierDetailsViewModel.supplierPaymentTypes.accountName = supplier.SupplierPaymentTypes.FirstOrDefault().AccountName; updateSupplierDetailsViewModel.supplierPaymentTypes.accountNumber = supplier.SupplierPaymentTypes.FirstOrDefault().AccountNumber; updateSupplierDetailsViewModel.supplierPaymentTypes.banks = new BankViewModels(); updateSupplierDetailsViewModel.supplierPaymentTypes.banks.id = supplier.SupplierPaymentTypes.FirstOrDefault().Bank.Id; updateSupplierDetailsViewModel.supplierPaymentTypes.banks.name = supplier.SupplierPaymentTypes.FirstOrDefault().Bank.Name; updateSupplierDetailsViewModel.supplierPaymentTypes.branch = supplier.SupplierPaymentTypes.FirstOrDefault().Branch; updateSupplierDetailsViewModel.supplierPaymentTypes.paymentModes = new PaymentTypeViewModels(); updateSupplierDetailsViewModel.supplierPaymentTypes.paymentModes.name = supplier.SupplierPaymentTypes.FirstOrDefault().PayementType.Name; updateSupplierDetailsViewModel.supplierPaymentTypes.paymentModes.id = supplier.SupplierPaymentTypes.FirstOrDefault().PayementType.Id; } var messageData = new { code = ReadOnlyValue.SuccessMessageCode, message = ReadOnlyValue.MessageSuccess }; var returnObject = new { updateSupplierDetailsViewModel = updateSupplierDetailsViewModel, messageCode = messageData }; return(Ok(returnObject)); } catch (Exception ex) { string errorLogId = _eventLogService.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name); var messageData = new { code = ReadOnlyValue.ErrorMessageCode, message = String.Format(ReadOnlyValue.MessageTaskmateError, errorLogId) }; var returnObject = new { messageCode = messageData }; return(Ok(returnObject)); } }
public IHttpActionResult GetAllSupplier() { try { IList <SupplierFormViewModel> supplierList = new List <SupplierFormViewModel>(); IEnumerable <Supplier> lstSupplier; lstSupplier = _supplier.GetAllSupplier(); foreach (Supplier supplier in lstSupplier) { SupplierFormViewModel supplierVM = new SupplierFormViewModel(); supplierVM.id = supplier.Id; supplierVM.registrationNo = supplier.RegNo; supplierVM.types.id = supplier.SupplierType.Id; supplierVM.isActive = supplier.IsActive; supplierVM.fullName = supplier.FullName; supplierVM.address = supplier.Address; supplierVM.routes.id = supplier.RouteId; supplierVM.types.id = supplier.SupplierTypeId; supplierList.Add(supplierVM); } var messageData = new { code = ReadOnlyValue.SuccessMessageCode, message = ReadOnlyValue.MessageSuccess }; var returnObject = new { supplierList = supplierList, messageCode = messageData }; return(Ok(returnObject)); } catch (Exception ex) { string errorLogId = _eventLogService.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name); var messageData = new { code = ReadOnlyValue.ErrorMessageCode, message = String.Format(ReadOnlyValue.MessageTaskmateError, errorLogId) }; var returnObject = new { messageCode = messageData }; return(Ok(returnObject)); } }
public IHttpActionResult CreateSuppliers(SupplierFormViewModel supplier) { try { string errorMessege = string.Empty; if (ModelState.IsValid) { Supplier entity = new Supplier(); entity.Address = supplier.address; entity.ContactNo = supplier.contactNumber; entity.FullName = supplier.fullName; entity.IsActive = supplier.isActive; entity.LeafTypeId = supplier.leafTypes.id; entity.NICNo = supplier.nicNo; entity.Notes = supplier.notes; entity.RegNo = supplier.registrationNo; entity.RouteId = supplier.routes.id; entity.SupplierTypeId = supplier.types.id; entity.CreatedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); entity.CreatedBy = "admin";//User.Identity.Name; entity.ModifiedBy = "admin"; entity.ModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); SupplierPaymentType supplierPaymentType = new SupplierPaymentType(); supplierPaymentType.SupplierId = entity.Id; supplierPaymentType.PaymentTypeId = supplier.supplierPaymentTypes.paymentModes.id; supplierPaymentType.AccountName = supplier.supplierPaymentTypes.accountName; supplierPaymentType.AccountNumber = supplier.supplierPaymentTypes.accountNumber; supplierPaymentType.BankId = supplier.supplierPaymentTypes.banks.id; supplierPaymentType.Branch = supplier.supplierPaymentTypes.branch; entity.SupplierPaymentTypes.Add(supplierPaymentType); foreach (SupplierFundViewModel fundsVm in supplier.supplierFunds) { SupplierFund supplierFund = new SupplierFund(); supplierFund.SupplierId = entity.Id; supplierFund.Amount = fundsVm.fundAmount; supplierFund.FundId = fundsVm.fundNames.id; supplierFund.FundModeId = fundsVm.fundModes.id; supplierFund.CreatedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); supplierFund.CreatedBy = "admin";//User.Identity.Name; supplierFund.ModifiedBy = "admin"; supplierFund.ModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"])); entity.SupplierFunds.Add(supplierFund); } _supplier.Add(entity, out errorMessege); } else { errorMessege = ReadOnlyValue.GeneralError; } var messageData = new { code = String.IsNullOrEmpty(errorMessege) ? ReadOnlyValue.SuccessMessageCode : ReadOnlyValue.ErrorMessageCode, message = String.IsNullOrEmpty(errorMessege) ? ReadOnlyValue.MessageSuccess : errorMessege }; var returnObject = new { messageCode = messageData }; return(Ok(returnObject)); } catch (Exception ex) { string errorLogId = _eventLogService.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name); var messageData = new { code = ReadOnlyValue.ErrorMessageCode, message = String.Format(ReadOnlyValue.MessageTaskmateError, errorLogId) }; var returnObject = new { messageCode = messageData }; return(Ok()); } }
public IActionResult Update(SupplierFormViewModel supplier) { ModelState.Remove("Comercial.Id"); ModelState.Remove("Comercial.InsertDate"); if (ModelState.IsValid) { if (supplier.SupplierPhysical != null) { //Atualiza Physical supplier.SupplierPhysical.UpdateDate = DateTime.Now; supplier.Celular.UpdateDate = DateTime.Now; supplier.SupplierPhysical.Contacts.Add(supplier.Celular); if (supplier.Comercial.Id == 0 && supplier.Comercial.Number != null) { supplier.Comercial.InsertDate = DateTime.Now; supplier.SupplierPhysical.Contacts.Add(supplier.Comercial); } else if (supplier.Comercial.Id > 0 && supplier.Comercial.Number == null) { _supplierRepository.RemoveContact(supplier.Comercial.Id); } else if (supplier.Comercial.Id > 0 && supplier.Comercial.Number != null) { supplier.Comercial.UpdateDate = DateTime.Now; supplier.SupplierPhysical.Contacts.Add(supplier.Comercial); } _supplierRepository.UpdateMain(supplier.SupplierPhysical); TempData["MSG_S"] = Message.MSG_S_001; return(RedirectToAction(nameof(Details), new { Id = supplier.SupplierPhysical.Id })); } else if (supplier.SupplierJuridical != null) { supplier.SupplierJuridical.UpdateDate = DateTime.Now; supplier.Celular.UpdateDate = DateTime.Now; supplier.SupplierJuridical.Contacts.Add(supplier.Celular); if (supplier.Comercial.Id == 0 && supplier.Comercial.Number != null) { supplier.Comercial.InsertDate = DateTime.Now; supplier.SupplierJuridical.Contacts.Add(supplier.Comercial); } else if (supplier.Comercial.Id > 0 && supplier.Comercial.Number == null) { _supplierRepository.RemoveContact(supplier.Comercial.Id); } else if (supplier.Comercial.Id > 0 && supplier.Comercial.Number != null) { supplier.Comercial.UpdateDate = DateTime.Now; supplier.SupplierJuridical.Contacts.Add(supplier.Comercial); } _supplierRepository.UpdateMain(supplier.SupplierJuridical); TempData["MSG_S"] = Message.MSG_S_001; return(RedirectToAction(nameof(Details), new { Id = supplier.SupplierJuridical.Id })); } else if (supplier.Address != null) { supplier.Address.UpdateDate = DateTime.Now; _supplierRepository.UpdateAddress(supplier.Address); TempData["MSG_S"] = Message.MSG_S_001; return(RedirectToAction(nameof(Details), new { Id = _supplierRepository.FindTheClientIdByAddress(supplier.Address.Id) })); } } return(View(nameof(Details), supplier)); }