public async Task <IActionResult> PostItemMaster([FromBody] MasterItemDto item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var itemMaster = ModelToData(item); _context.ItemMaster.Add(itemMaster); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ItemMasterExists(itemMaster.ItemMasterIdPk)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetItemMaster", new { id = itemMaster.ItemMasterIdPk }, item)); }
public async Task <IActionResult> PutItemMaster([FromRoute] int id, [FromBody] MasterItemDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != model.ProductNumber) { return(BadRequest()); } var itemMaster = ModelToData(model); _context.Entry(itemMaster).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemMasterExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private bool FilterCandidates(object obj) { MasterItemDto c = (MasterItemDto)obj; return(filters.Values .Aggregate(true, (prevValue, predicate) => prevValue && predicate(c))); }
private void Btn_Simpan_Click(object sender, RoutedEventArgs e) { try { _itemServices = new ItemServices(); if (JenisBarang.SelectedItem.GetType() != typeof(ItemType)) { MessageBox.Show("Jenis Barang harus dipilih", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (string.IsNullOrEmpty(NamaBarang.Text)) { MessageBox.Show("Nama Barang tidak boleh kosong", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (string.IsNullOrEmpty(HargaBarang.Text)) { MessageBox.Show("Harga Barang tidak boleh kosong", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (string.IsNullOrEmpty(OngkosKontainer.Text)) { MessageBox.Show("Ongkos Kontainer tidak boleh kosong", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } var Dto = new MasterItemDto(); Dto.NAMA_BARANG = NamaBarang.Text; Dto.HARGA = decimal.Parse(HargaBarang.Text); Dto.JENIS_BARANG = (ItemType)JenisBarang.SelectedItem; Dto.ONGKOS_CONTAINER = decimal.Parse(OngkosKontainer.Text); Dto.STATUS = Core.Status.Aktif; Dto.ID = int.Parse(IdBarang.Text); var DataExisting = _itemServices.GetAll().Where(x => !string.IsNullOrEmpty(x.NAMA_BARANG) && x.NAMA_BARANG.ToUpper() == Dto.NAMA_BARANG.ToUpper() && x.JENIS_BARANG == Dto.JENIS_BARANG).FirstOrDefault(); if (DataExisting != null && DataExisting.ID != Dto.ID) { MessageBox.Show("Barang sudah ada di database", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } _itemServices.Save(Dto); MessageBox.Show("Update Data Sukses", "Sukses", MessageBoxButton.OK, MessageBoxImage.Information); CloseWin(); } catch (Exception exp) { MessageBox.Show("Update Data Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void Save(MasterItemDto Dto) { var Db = AutoMapper.Mapper.Map <master_item>(Dto); Uow = new UnitOfWorks(); _masterItemRepo = Uow.GetGenericRepository <master_item>(); _masterItemRepo.InsertOrUpdate(Db); Uow.SaveChanges(); }
private ItemMaster ModelToData(MasterItemDto model) { var data = new ItemMaster { ItemMasterIdPk = model.ProductNumber, Impack = model.PackSize, Imdescription = model.Description, ImimageData = !string.IsNullOrEmpty(model.ProductImage) ? Convert.FromBase64String(model.ProductImage) : null, ImisHazardousMaterial = model.IsHazardousMaterial, ImexpirationDate = DateTime.ParseExact(model.ExpirationDate, "MM/dd/yyyy", CultureInfo.InvariantCulture), ImcostCenterCode = int.Parse(model.CostCenterCode.Replace("-", "")), ImunitPrice = model.UnitPrice, Imwidth = model.Width, Imlength = model.Length, Imheight = model.Height, ImisPrePack = model.IsPrePack, ImprePackStyle = model.PrePack }; return(data); }
private MasterItemDto DataToModel(ItemMaster itemMaster) { var model = new MasterItemDto { ProductNumber = itemMaster.ItemMasterIdPk, PackSize = itemMaster.Impack, Description = itemMaster.Imdescription, ProductImage = itemMaster.ImimageData != null ? Convert.ToBase64String(itemMaster.ImimageData, 0, itemMaster.ImimageData.Length) : null, IsHazardousMaterial = itemMaster.ImisHazardousMaterial, ExpirationDate = itemMaster.ImexpirationDate.ToString("MM/dd/yyyy"), CostCenterCode = itemMaster.ImcostCenterCode.ToString("####-##-##"), UnitPrice = itemMaster.ImunitPrice, Width = itemMaster.Imwidth, Length = itemMaster.Imlength, Height = itemMaster.Imheight, IsPrePack = itemMaster.ImisPrePack, PrePack = itemMaster.ImprePackStyle }; return(model); }