public void UpdateSuppiler(SupplierDto dto) { if (dto.IsCompany) { if (string.IsNullOrEmpty(dto.Code)) { throw new BingoX.LogicException("爲公司時編號不能爲空"); } var exist = repository.Get(x => x.Code == dto.Code); if (exist != null && exist.ID != dto.ID) { throw new BingoX.LogicException("編號已經存在"); } } Supplier entity = repository.GetId(dto.ID); if (entity == null) { throw new BingoX.AspNetCore.NotFoundEntityException(); } entity.Modified(this); entity.ManName = dto.ManName; entity.ManTel = dto.ManTel; entity.OfficeTel = dto.OfficeTel; entity.Code = dto.Code; entity.IsCompany = dto.IsCompany; entity.Address = dto.Address; entity.State = dto.State == "1" ? CommonState.Enabled : CommonState.Disabled; repository.Update(entity); repository.UnitOfWork.Commit(); resourceService.ChangedSupplier(); }
private void PerformSave(ExcelImportEventArgs arg) { ExcelSheet excelSheet = arg.Result; // Extract data from imported Excel sheet List <SupplierDto> Suppliers = new List <SupplierDto>(); for (int index = excelSheet.DataStartRowIndex; index < excelSheet.Rows.Count; index++) { ExcelSheetRow excelRow = excelSheet.Rows[index]; SupplierDto Supplier = new SupplierDto(); ExtractImportedSheetRow(Supplier, excelRow); Suppliers.Add(Supplier); } // Save batch using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey)) { SupplierFacade facade = new SupplierFacade(uow); IFacadeUpdateResult <SupplierData> result = facade.SaveSuppliers(Suppliers); if (result.IsSuccessful) { arg.IsSuccessful = true; arg.Message = string.Format("Batch save done. \\nTotal {0} rows.", Suppliers.Count); } else { arg.IsSuccessful = false; // Deal with Update result ProcUpdateResult(result.ValidationResult, result.Exception); } } }
public async Task <ApiJsonResult> Create(int?tenantId, SupplierDto data) { var result = new ApiJsonResult(); if (string.IsNullOrEmpty(data.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is not null"; return(result); } if (string.IsNullOrEmpty(data.CustomerCode)) { result.Code = CodeModel.Fail; result.Message = "Customer Code is not null"; return(result); } if (await ValidateDuplicateCode(data.Id, data.CustomerCode)) { result.Code = CodeModel.Fail; result.Message = "Customer Code is duplicated"; return(result); } var supplier = _mapper.Map <Customer>(data); supplier.TenantId = tenantId.Value; supplier.CustomerTypeId = CustomerType.Supplier; _unitOfWork.CustomerRepository.Create(supplier); await _unitOfWork.Commit(); return(result); }
public void AddSuppiler(SupplierDto dto) { Supplier entity = new Supplier(); if (dto.IsCompany) { if (string.IsNullOrEmpty(dto.Code)) { throw new BingoX.LogicException("爲公司時編號不能爲空"); } if (repository.Exist(x => x.Code == dto.Code)) { throw new BingoX.LogicException("編號已經存在"); } } entity.Created(this); entity.Name = dto.Name; entity.ManName = dto.ManName; entity.ManTel = dto.ManTel; entity.OfficeTel = dto.OfficeTel; entity.Address = dto.Address; entity.Code = dto.Code; entity.IsCompany = dto.IsCompany; entity.State = dto.State == "1" ? CommonState.Enabled : CommonState.Disabled; repository.Add(entity); repository.UnitOfWork.Commit(); resourceService.ChangedSupplier(); }
public async Task Put(int id, [FromBody] SupplierDto value) { await mediator.Send(new UpdateSupplierRequest() { dto = value }); }
public async Task <ServiceResponse <SupplierDto> > UpdateAsync(SupplierDto supplier, int userId) { if (supplier == null) { throw new ArgumentNullException(nameof(supplier)); } var existentEntity = await UnitOfWork.Get <Supplier>().GetAsync(t => t.ID == supplier.ID); if (existentEntity == null) { return(new ServiceResponse <SupplierDto>(ServiceResponseStatus.NotFound)); } var entity = supplier.ToEntity(); existentEntity.Attachments = GetAttachments(existentEntity.ID).ToList(); existentEntity.Recommendations = GetRecommendations(existentEntity.ID).ToList(); existentEntity .UpdateFields(entity) .UpdateAttachments(entity, UnitOfWork, userId) .UpdateRecommendations(entity, UnitOfWork, userId) .UpdateModifiedFields(userId); UnitOfWork.Get <Supplier>().Update(existentEntity); await UnitOfWork.SaveAsync(); return(new SuccessResponse <SupplierDto>()); }
/// <summary> /// /// </summary> private void ShowDetail() { SupplierDto mm = null; if (Index != -1) { mm = Data[Index]; } if (mm != null) { txtCode.Text = mm.Code; txtOldCode.Text = mm.OldCode; txtName.Text = mm.Name; txtAddr1.Text = mm.Address1; txtAddr2.Text = mm.Address2; txtCity.Text = mm.City; txtZipCode.Text = mm.ZipCode; txtPhone1.Text = mm.Phone1; txtFax1.Text = mm.Fax1; chkStatus.Checked = mm.Status == 1 ? true : false; txtEmail.Text = string.Empty; lnkEmail.Text = mm.Email; } Flag = Flag.IDLE; }
public void Suppliers_Create() { // Arrange db = new AlexaDbContextTest(); supplierService = new SupplierService(new SupplierRepositoryTest(db), new GroupRepositoryTest(db)); groupService = new GroupService(new SupplierRepositoryTest(db), new GroupRepositoryTest(db)); controller = new SuppliersController(supplierService, groupService); var supplier = new SupplierDto { ID = 5, Name = "test", Address = "test", Email = "test", Phone = "123 456 789", Groups = new List <GroupDto>() { groupService.GetById(0) } }; // Act ViewResult result_1 = controller.Create(supplier) as ViewResult; ViewResult result_2 = controller.Details(5) as ViewResult; // Assert Assert.IsNotNull(result_2); Assert.IsInstanceOfType(result_2.ViewData.Model, typeof(SupplierDto)); var supplier_edit = (SupplierDto)result_2.ViewData.Model; Assert.AreEqual(supplier_edit.Name, "test"); }
public async Task UpdateAsync(long supplierId, IDictionary <string, object> changes) { Supplier updatedSupplier = null; try { using (var uow = await this._billingUnitOfWorkFactory.CreateAsync().ConfigureAwait(false)) { await uow.Suppliers.UpdateAsync(supplierId, changes).ConfigureAwait(false); await uow.CommitAsync().ConfigureAwait(false); updatedSupplier = await uow.Suppliers.GetByIdAsync(supplierId).ConfigureAwait(false); } } catch (Exception ex) { Debug.WriteLine("Error updating supplier from service."); Debug.WriteLine(ex); throw; } var addedSupplierDto = new SupplierDto(updatedSupplier); this._updated_Subject.OnNext(new[] { addedSupplierDto }); }
private void TransferData(SupplierDto dto, Supplier instance) { instance.Name = dto.Name; instance.AddressLine1 = dto.AddressLine1; instance.AddressLine2 = dto.AddressLine2; instance.Country = dto.Country; instance.CountryState = dto.CountryState; instance.City = dto.City; instance.ZipCode = dto.ZipCode; instance.ContactPerson = dto.ContactPerson; instance.ContactPhone = dto.ContactPhone; instance.ContactEmail = dto.ContactEmail; instance.ContactFax = dto.ContactFax; instance.CategoryId = dto.CategoryId; instance.NationId = dto.NationId; instance.AllowTakeOut = dto.AllowTakeOut; instance.AllowReserve = dto.AllowReserve; instance.AllowBringWine = dto.AllowBringWine; instance.DayStartTime = dto.DayStartTime; instance.DayEndTime = dto.DayEndTime; instance.Grade = dto.Grade; instance.Logo = dto.Logo; instance.Website = dto.Website; instance.ProductCatalogId = dto.ProductCatalogId; }
//private readonly BehaviorSubject<bool> _isBusy_BehaveiorSubject; //public IObservable<bool> IsBusyChanged { get; } //public IQbservable<Supplier> Suppliers => throw new NotImplementedException(); // WRITE public async Task <SupplierDto> CreateAndAddAsync(IDictionary <string, object> data) { //using (var uow = this._billingUowFactoryMethod.Invoke()) Supplier addedSupplier = null; using (var uow = await this._billingUnitOfWorkFactory.CreateAsync().ConfigureAwait(false)) { try { addedSupplier = await uow.Suppliers.CreateAndAddAsync(data).ConfigureAwait(false); await uow.CommitAsync().ConfigureAwait(false); } catch (Exception) { Debug.WriteLine("error creating supplier from service"); throw; } } if (addedSupplier == null) { return(null); } var addedSupplierDto = new SupplierDto(addedSupplier); this._added_Subject.OnNext(addedSupplierDto); return(addedSupplierDto); }
public Supplier(ISqlExecutor executor, IMapper mapper, SupplierPoco supplierPoco, SupplierDto dto) { _supplierValue = supplierPoco; _supplierDto = dto; _sqlExecutor = executor; _supplierMapper = mapper; }
public ActionResult Create([Bind(Include = "ID,Name,Address,Email,Phone,SelectedItems")] SupplierDto supplier) { if (ModelState.IsValid) { if (supplier.SelectedItems != null && supplier.SelectedItems.Length > 0) { supplier.Groups = new List <GroupDto>(); /* Split SelectedGroups by ';' */ string[] groupStrs = supplier.SelectedItems.Split(';'); /* Iterate through groupStrs, add selected groups into supplierDb and remeber tested groups */ foreach (string groupStr in groupStrs) { try { int id = Int32.Parse(groupStr.Replace("Group_", "")); supplier.Groups.Add(GroupService.GetById(id)); } catch (FormatException) { ; } } } SupplierService.Add(supplier); return(RedirectToAction("Index")); } return(View(supplier)); }
public async Task <IActionResult> UpdateSupplier(int id, SupplierDto supplierDto) { var supFromRepository = await _invRepo.GetSupplier(id); if (supFromRepository == null) { return(BadRequest("supplier not available")); } if (await _context.Suppliers.AnyAsync(a => a.Name == supplierDto.Name && a.Id != supplierDto.Id)) { return(BadRequest("Supplier already exist")); } supFromRepository.Name = supplierDto.Name; supFromRepository.ContactNumber = supplierDto.ContactNumber; supFromRepository.Email = supplierDto.Email; supFromRepository.Address = supplierDto.Address; supFromRepository.Type = supplierDto.Type; if (await _invRepo.SaveAll()) { return(NoContent()); } throw new System.Exception($"Updating supplier {id} failed on save"); }
public async Task <int> Post([FromBody] SupplierDto value) { return(await mediator.Send(new CreateSupplierRequest() { dto = value })); }
public IHttpActionResult Put(int id, SupplierDto dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dto.SupplierID) { return(BadRequest()); } try { repo.Put(dto); } catch (DbUpdateConcurrencyException) { if (!repo.SupplierExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task Save_should_save_a_supplier_to_the_db() { using (var store = NewDocumentStore()) { using (var session = store.OpenAsyncSession()) { // Arrange var dto = new SupplierDto { Id = default(string), Name = "Ademir", Cnpj = "cnpj", Cpf = "cpf", Municipio = "Belem" }; var service = GetSupplierService(session); // Act var model = await service.Save(dto); // Assert model.Success.Should().BeTrue(); model.Message.Should().Be("Criou cliente Ademir"); var actual = await session.LoadAsync<Supplier>("Suppliers-1"); actual.Name.Should().Be("Ademir"); actual.Cnpj.Should().Be("cnpj"); actual.Cpf.Should().Be("cpf"); actual.Municipio.Should().Be("Belem"); actual.AuditInfo.Username.Should().NotBeNullOrEmpty(); actual.AuditInfo.Updated.Should().BeCloseTo(DateTime.Now, 2000); } } }
public async Task <ActionResult> Put(int id, [FromBody] SupplierDto newSupplier) { try { var supplierWaitingForUpdate = await _context.Suppliers.FirstOrDefaultAsync(r => r.SupplierId == id); if (supplierWaitingForUpdate == null) { return(NotFound("Couldnt find the item")); } if (newSupplier.Name != null) { supplierWaitingForUpdate.Name = newSupplier.Name; } if (newSupplier.Multiplier > 0) { supplierWaitingForUpdate.Multiplier = newSupplier.Multiplier; } if (newSupplier.Address != null) { supplierWaitingForUpdate.Address = newSupplier.Address; } await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(418, ex.Message)); } }
public IActionResult UpdateSupplier(SupplierDto supplierDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _supplierService.Update(supplierDto); var integrationEventData = JsonConvert.SerializeObject(new { id = supplierDto.Id, companyName = supplierDto.CompanyName }); PublishToMessageQueue("suppliers.update", integrationEventData); _logger.LogInformation($"Supplier updated, id {supplierDto.Id}"); return(NoContent()); } catch (DbQueryResultNullException e) { return(NotFound(e.Message)); } }
public async Task <SupplierDto> UpdateAsync(SupplierDto customerDto) { var supplier = _mapper.Map <Supplier>(customerDto); var result = await _supplierRepository.UpdateAsync(supplier); return(_mapper.Map <SupplierDto>(result)); }
public async Task <ActionResult> Post([FromBody] SupplierDto newSupplier) { try { Supplier supplier = _mapper.Map <Supplier>(newSupplier); if (supplier.Name == null) { return(BadRequest("Enter a valid supplier name")); } if (supplier.Address == null) { return(BadRequest("Enter a valid supplier address")); } if (supplier.Multiplier <= 0) { return(BadRequest("Enter a valid supplier multiplier")); } _context.Suppliers.Add(supplier); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(418, ex.Message)); } }
private void btnUpdate_Click(object sender, EventArgs e) { SupplierDto supplierDto = new SupplierDto(); ListViewItem selectedItem = lstViewSupplier.FocusedItem; if (selectedItem != null) { supplierDto = (SupplierDto)selectedItem.Tag; if (MessageBox.Show("Güncellemek istediğinize emin misiniz?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { supplierDto.ContactName = txtContactName.Text; supplierDto.Name = txtCompanyName.Text; supplierDto.Title = txtTitle.Text; supplierDto.Country = txtCountry.Text; bool result = northwindServices.UpdateSupplier(supplierDto); if (result) { MessageBox.Show("Başarıyla Güncellendi"); lstViewSupplier.Items.Clear(); FrmSupplier_Load(new object(), new EventArgs()); } } catch (Exception) { MessageBox.Show("HATA!"); } } } }
public async Task <SupplierDto> AddAsync(SupplierDto supplierDto) { var supplier = _mapper.Map <Supplier>(supplierDto); var result = await _supplierRepository.AddAsync(supplier); return(_mapper.Map <SupplierDto>(result)); }
private void BtnAdd_Click(object sender, EventArgs e) { SupplierDto supplierDto = new SupplierDto(); supplierDto.Name = txtCompanyName.Text; supplierDto.ContactName = txtContactName.Text; supplierDto.Title = txtTitle.Text; supplierDto.Country = txtCountry.Text; if (northwindServices.AddSupplier(supplierDto)) { MessageBox.Show(" Eklendi"); txtCompanyName.Text = ""; txtContactName.Text = ""; txtCountry.Text = ""; txtTitle.Text = ""; lstViewSupplier.Items.Clear(); FrmSupplier_Load(new object(), new EventArgs()); } else { MessageBox.Show("Product Eklenemedi!"); } }
private void btnDelete_Click(object sender, EventArgs e) { SupplierDto supplierDto = new SupplierDto(); ListViewItem selectedItem = lstViewSupplier.FocusedItem; if (selectedItem != null) { supplierDto = (SupplierDto)selectedItem.Tag; if (MessageBox.Show("Silmek istediğinize emin misiniz?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { if (northwindServices.RemoveSupplier(supplierDto)) { MessageBox.Show("Kayıt başarıyla silindi!"); lstViewSupplier.Items.Clear(); FrmSupplier_Load(new object(), new EventArgs()); } } catch (Exception) { MessageBox.Show("Bu kayıt tabloları etkilediği için silinemez!"); } } } }
public HttpResponseMessage UpdateSupplier(int id, [FromBody] SupplierDto supplier) { supplier.Id = id; _service.UpdateSupplier(supplier); _service.ApplyChanges(); return(Request.CreateResponse(HttpStatusCode.OK, $"Suppliers updated{supplier.Name}")); }
public async Task <IActionResult> Put(SupplierDto supplierDto, int id) { try { if (id == 0) { return(BadRequest("Id cannot be 0")); } Supplier temp = new Supplier(supplierDto); bool hasOverwritten = await _putService.PutAsync(temp, id); IEnumerable <Supplier> result = await _getService.GetAsync(id); if (hasOverwritten) { return(Ok(result.FirstOrDefault())); } return(CreatedAtAction( nameof(Put), id, result.FirstOrDefault())); } catch (Exception exception) { _exceptionLogger.LogException(exception, nameof(SuppliersController), _logger); throw; } }
public IActionResult OnGet(int?id) { var t = Request.Cookies["logon"]; if (t == null) { return(RedirectToPage("../Accounts/Login")); } if (t == "false") { return(RedirectToPage("../Accounts/Login")); } if (id == null) { return(NotFound()); } Supplier = _service.GetSupplier(id ?? default(int)); if (Supplier == null) { return(NotFound()); } return(Page()); }
public async Task UpdateAsync(SupplierDto supplierDto) { // Adds an analayzer to the name property in FermentableDto object. await _client.MapAsync <SupplierDto>(d => d.Properties(p => p.String(s => s.Name(n => n.Name).Analyzer("autocomplete")))); var index = await _client.IndexAsync <SupplierDto>(supplierDto); }
public override async Task <ISupplierData> CreateSupplierAsync(SupplierDto dto) { ISupplierData data = await _services.GetSupplierDataServices().GetAsyncSupplierDo(dto.NUM_PROVEE).ConfigureAwait(false); data.Value = dto; return(data); }
public Supplier(ISqlExecutor executor) { _sqlExecutor = executor; _supplierValue = new SupplierPoco(); _supplierDto = new SupplierDto(); InitializeMapping(); }
public async Task<BaseUpdateModel<SupplierDto>> Save(SupplierDto dto) { var entity = dto.Id.IsNullOrEmpty() ? new Supplier() : await Session.LoadAsync<Supplier>(dto.Id); if (entity == null) throw new NotFoundException($"Não existe cliente com Id {dto.Id}"); SetUpdateText(dto); Mapper.Map(dto, entity); UpdateAuditInfo(entity); await Session.StoreAsync(entity); await Session.SaveChangesAsync(); dto.Id = entity.Id; return new BaseUpdateModel<SupplierDto>(dto, $"{UpdateText} cliente {entity.Name}", true); }
public async Task<SupplierDto> GetById(string id) { if (id.IsNullOrEmpty()) throw new ArgumentNullException(nameof(id)); var entity = await Session.LoadAsync<Supplier>(id); if (entity == null) throw new NotFoundException($"Não existe um cliente com Id {id.FromRavenId()}"); var dto = new SupplierDto { Id = entity.Id, Name = entity.Name, Municipio = entity.Municipio, Cpf = entity.Cpf, Cnpj = entity.Cnpj }; return dto; }
public async Task GetById_should_retrieve_a_supplier_from_the_db() { using (var store = NewDocumentStore()) { // Arrange using (var session = store.OpenAsyncSession()) { var dto = new SupplierDto { Id = default(string), Name = "Ademir", Cnpj = "cnpj", Cpf = "cpf", Municipio = "Belem" }; var service = GetSupplierService(session); await service.Save(dto); } using (var session = store.OpenAsyncSession()) { // Act var service = GetSupplierService(session); var dto = await service.GetById("suppliers-1"); // Assert dto.Id.Should().Be("suppliers-1"); dto.Name.Should().Be("Ademir"); dto.Cnpj.Should().Be("cnpj"); dto.Cpf.Should().Be("cpf"); dto.Municipio.Should().Be("Belem"); } } }