private SupplierEditModel BuildSupplierEditModel(Supplier entity) { var supplierEditModel = new SupplierEditModel(); supplierEditModel.SupplierID = entity.SupplierID; supplierEditModel.SupplierCode = entity.SupplierCode; supplierEditModel.SupplierCompanyName = entity.SupplierCompanyName; supplierEditModel.ParentSupplierID = entity.ParentSupplierID; supplierEditModel.ParentSupplierName = entity.ParentSupplier.SupplierCompanyName; supplierEditModel.IsHaulier = entity.IsHaulier; supplierEditModel.IsFactor = entity.IsFactor; supplierEditModel.CompanyID = entity.CompanyID; supplierEditModel.CompanyName = entity.Company.CompanyName; if (entity.NoteID.HasValue) { supplierEditModel.NoteID = entity.NoteID; entity.Note = _noteService.NoteById(entity.NoteID.Value); supplierEditModel.Notes = entity.Note.NoteText; } supplierEditModel.IsActive = entity.IsActive ?? true; supplierEditModel.CreatedDate = entity.CreatedDate.HasValue ? entity.CreatedDate.ToString() : string.Empty; supplierEditModel.CreatedBy = entity.CreatedBy.HasValue ? entity.CreatedBy.Value.ToString() : string.Empty; supplierEditModel.UpdatedDate = entity.UpdatedDate.HasValue ? entity.UpdatedDate.ToString() : string.Empty; supplierEditModel.UpdatedBy = entity.UpdatedBy.HasValue ? entity.UpdatedBy.Value.ToString() : string.Empty; //foreach (var supplierItem in entity.SupplierItems) // supplierEditModel.SupplierItems.Add(BuildSupplierItemEditModel(supplierItem)); ////////////////////////// supplierEditModel.SupplierLocations = _locationOrchestra.BuildSupplierLocationModels(entity.SupplierLocations); supplierEditModel.SupplierDepartments = _departmentOrchestra.BuildSupplierDepartmentModels(entity.SupplierDepartments); supplierEditModel.SupplierContacts = _contactOrchestra.BuildSupplierContactModels(entity.SupplierContacts); return(supplierEditModel); }
public SupplierEditModel CreateSupplier(SupplierEditModel model) { try { var item = ApplyChanges(model); item.NoteID = SaveNote(model); if (model.SupplierID == Guid.Empty) { item.ObjectState = ObjectState.Added; model.SupplierID = item.SupplierID; _supplierService.Insert(item); } else { item.ObjectState = ObjectState.Modified; _supplierService.Update(item); } SaveSupplierDataIn3lists(model); } catch (Exception ex) { throw new ApplicationException("Creating Supplier failed", ex); } return(model); }
private void SupplierItemsOf3lists(SupplierEditModel model, Guid id) { foreach (var item in model.SupplierContacts) { item.SupplierID = id; item.CreatedDate = !string.IsNullOrEmpty(model.CreatedDate) ? DateTime.Parse(model.CreatedDate).ToString() : DateTime.Now.ToString(); item.CreatedByUserID = _principal.Id.ToString(); item.UpdatedDate = DateTime.Now.ToString(); item.UpdatedByUserID = _principal.Id.ToString(); item.IsActive = true; } foreach (var item in model.SupplierDepartments) { item.SupplierID = id; item.CreatedDate = !string.IsNullOrEmpty(model.CreatedDate) ? DateTime.Parse(model.CreatedDate).ToString() : DateTime.Now.ToString(); item.CreatedBy = _principal.Id.ToString(); item.UpdatedDate = DateTime.Now.ToString(); item.UpdatedBy = _principal.Id.ToString(); item.IsActive = true; } foreach (var item in model.SupplierLocations) { item.SupplierID = id; item.CreatedDate = !string.IsNullOrEmpty(model.CreatedDate) ? DateTime.Parse(model.CreatedDate).ToString() : DateTime.Now.ToString(); item.CreatedBy = _principal.Id.ToString(); item.UpdatedDate = DateTime.Now.ToString(); item.UpdatedBy = _principal.Id.ToString(); item.IsActive = true; } }
public ViewResult Create() { var SupplierModel = new SupplierEditModel(); ViewBag.FormAspAction = "Create"; return(View("Edit", SupplierModel)); }
public SupplierEditModel GetSupplierModelBySupplierID(Guid supplierID) { Supplier entity = _supplierService.GetSupplierByIdFromRepo(supplierID); SupplierEditModel supplierModel = entity != null ? BuildSupplierEditModel(entity) : null; return(supplierModel); }
public ActionResult Create() { var viewModel = new SupplierEditModel() { Supplier = new SupplierDto() }; return(View(viewModel)); }
public async Task <IActionResult> Create([FromForm] SupplierEditModel model) { var Supplier = new Supplier(); _mapper.Map(model, Supplier); await _SupplierRepository.StoreNewAsync(Supplier); return(RedirectToAction("Index")); }
private Guid UpdateNote(SupplierEditModel model, ApplicationUser author) { var note = _noteService.Find(model.NoteID.Value); note.NoteText = model.Notes; note.NoteDescription = model.NoteDescription; note.ObjectState = ObjectState.Modified; _noteService.Update(note); return(note.NoteID); }
public ActionResult Edit(SupplierEditModel model) { if (!ModelState.IsValid) { return(View(model)); } model.Supplier.Updated = DateTime.Now; model.Supplier.ByUser = User.Identity.Name; _service.Update(model.Supplier); return(RedirectToAction("Index")); }
public void Supplier_SupplierEdit_ReturnsSupplierIndexView() { var viewModel = new SupplierEditModel() { Supplier = new SupplierDto() { Name = "Test" } }; var result = _suppliersController.Edit(viewModel) as RedirectToRouteResult; Assert.That(result.RouteValues["Action"], Is.EqualTo("Index")); }
public void Supplier_SupplierEdit_ReturnsSupplierServiceUpdate() { var viewModel = new SupplierEditModel() { Supplier = new SupplierDto() { Name = "Test" } }; var result = _suppliersController.Edit(viewModel) as RedirectToRouteResult; _supplierService.Received().Update(viewModel.Supplier); }
private Guid CreateNote(SupplierEditModel model, ApplicationUser author) { var note = new Note { NoteID = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]), NoteText = model.Notes, NoteDescription = model.NoteDescription, // IsActive = true, ObjectState = ObjectState.Added }; _noteService.Insert(note); return(note.NoteID); }
public void SuppliersController_PostEditViewModel_DbSetReceivedFind() { var viewModel = new SupplierEditModel { Supplier = new SupplierDto() { Name = "Test", IsDeleted = false } }; _suppliersController.Edit(viewModel); _dbSet.Received(1).Attach(Arg.Any <Supplier>()); _context.Received(1).SaveChanges(); }
public void SuppliersController_PostCreateViewModel_DbSetReceivedAddAndContextReceivedSaveChanges() { var viewModel = new SupplierEditModel { Supplier = new SupplierDto() { Name = "Test", IsDeleted = false } }; _suppliersController.Create(viewModel); _dbSet.Received(1).Add(Arg.Any <Supplier>()); _context.Received(1).SaveChanges(); }
public async Task <IActionResult> Edit(int Id, [FromForm] SupplierEditModel model) { var Supplier = await _SupplierRepository.GetByIdAsync(Id); if (Supplier == null) { Response.StatusCode = NotFound().StatusCode; return(View("Supplier not found!")); } _mapper.Map(model, Supplier); await _SupplierRepository.UpdateAsync(Supplier); return(RedirectToAction("Index")); }
public ActionResult Edit(int id) { var modelDto = _service.GetSingle(id); if (modelDto == null) { return(HttpNotFound()); } var viewModel = new SupplierEditModel() { Supplier = modelDto }; return(View(viewModel)); }
public IActionResult Edit(int id) { var supplierExists = suppliers.Exists(id); if (!supplierExists) { return(RedirectToAction(nameof(Local))); } SupplierEditModel supplier = this.suppliers.ById(id); return(View(new SupplierFormModel { Name = supplier.Name, IsImporter = supplier.IsImporter })); }
private void SaveSupplierDataIn3lists(SupplierEditModel model) { Dictionary <string, Guid> locaDic = new Dictionary <string, Guid>(); Dictionary <string, Guid> depaDic = new Dictionary <string, Guid>(); foreach (var item in model.SupplierLocations) { var result = _locationOrchestra.CreateSupplierLocation(item); //if (IsIdGuid(item.SupplierLocationID.ToString())) /////////////////////////////// if (!item.ItemAdding && !item.ItemDeleting) { item.x_SupplierLocationID = item.SupplierLocationID.ToString(); } locaDic[item.x_SupplierLocationID] = result.SupplierLocationID; } foreach (var item in model.SupplierDepartments) { var locaGuidList = new List <Guid>(); foreach (var xId in item.SelectedLocationIds) { locaGuidList.Add(locaDic[xId]); } var result = _departmentOrchestra.CreateSupplierDepartment(item, locaGuidList); //if (IsIdGuid(item.SupplierDepartmentID.ToString())) //////////////////////////////// if (!item.ItemAdding && !item.ItemDeleting) { item.x_SupplierDepartmentID = item.SupplierDepartmentID.ToString(); } depaDic[item.x_SupplierDepartmentID] = result.SupplierDepartmentID; } foreach (var item in model.SupplierContacts) { var locaGuidList = new List <Guid>(); foreach (var xId in item.SelectedLocationIds) { locaGuidList.Add(locaDic[xId]); } var depaGuidList = new List <Guid>(); foreach (var xId in item.SelectedDepartmentIds) { depaGuidList.Add(depaDic[xId]); } _contactOrchestra.CreateSupplierContact(item, locaGuidList, depaGuidList); } }
private Guid?SaveNote(SupplierEditModel model) { if (string.IsNullOrEmpty(model.NoteDescription)) { model.NoteDescription = "?!"; // <--- Paul Edwards } if (!string.IsNullOrEmpty(model.Notes)) { if (model.NoteID == null || model.NoteID == Guid.Empty) { model.NoteID = CreateNote(model, _principal); } else { model.NoteID = UpdateNote(model, _principal); } } return(model.NoteID); }
private Supplier ApplyChanges(SupplierEditModel model) { var item = new Supplier(); item.SupplierID = model.SupplierID == Guid.Empty ? PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]) : model.SupplierID; SupplierItemsOf3lists(model, item.SupplierID); item.SupplierCompanyName = model.SupplierCompanyName; item.SupplierCode = model.SupplierCode; item.CreatedDate = !string.IsNullOrEmpty(model.CreatedDate) ? DateTime.Parse(model.CreatedDate) : DateTime.Now; item.CreatedBy = _principal.Id; item.UpdatedDate = DateTime.Now; item.UpdatedBy = _principal.Id; item.IsActive = true; item.IsFactor = model.IsFactor; item.IsHaulier = model.IsHaulier; item.ParentSupplierID = model.ParentSupplierID; item.CompanyID = model.CompanyID; return(item); }
public ActionResult Edit(SupplierEditModel model) { if (this.ModelState.IsValid) { var supplierName = this.suppliers .GetAll() .FirstOrDefault(x => x.Name.ToLower() == model.Name.ToLower()); if (supplierName == null) { var supplier = this.Mapper.Map<Supplier>(model); this.suppliers.Update(model.Id, supplier); TempData["Success"] = GlobalConstants.SupplierUpdatedNotify; } else { TempData["Warning"] = GlobalConstants.SupplierExistsNotify; } return this.Redirect("/Admin/Suppliers/Index"); } return this.View(model); }
public IActionResult SaveSupplier(SupplierEditModel model) { var efSupplier = model.ConvertToEntity(); }