public int sppInsert(spp sppData) { //spp sppRequest = (spp)convertJsonToType(sppRequestJson, typeof(Model.spp)); sppData.verification_date = DateTime.Now; sppData.status = "Sukses"; mspbu.spps.Add(sppData); return mspbu.SaveChanges(); //int rowAffected = mspbu.SaveChanges(); //return rowAffected + " row inserted"; }
public int sppUpdate(spp sppData) { //spp sppRequest = (spp)convertJsonToType(sppRequestJson, typeof(Model.spp)); spp sppFound = mspbu.spps.Find(sppData.Id); if (sppFound != null) { sppFound.name = (sppData.name != null) ? sppData.name : sppFound.name; sppFound.address = (sppData.address != null) ? sppData.address : sppFound.address; sppFound.police_no = (sppData.police_no != null) ? sppData.police_no : sppFound.police_no; sppFound.shipment_no = (sppData.shipment_no != null) ? sppData.shipment_no : sppFound.shipment_no; sppFound.volume = (sppData.volume != null) ? sppData.volume : sppFound.volume; sppFound.dens_temp = (sppData.dens_temp != null) ? sppData.dens_temp : sppFound.dens_temp; sppFound.buyer = (sppData.buyer != null) ? sppData.buyer : sppFound.buyer; sppFound.product = (sppData.product != null) ? sppData.product : sppFound.product; sppFound.print_date = (sppData.print_date != null) ? sppData.print_date : sppFound.print_date; sppFound.verification_date = (sppData.verification_date != null) ? sppData.verification_date : sppFound.verification_date; sppFound.status = (sppData.status != null) ? sppData.status : sppFound.status; mspbu.Entry(sppFound).State = EntityState.Modified; return mspbu.SaveChanges(); } return -1; //int rowAffected = mspbu.SaveChanges(); //return rowAffected + " row updated"; }
public List<spp> sppGetWhere(spp sppData) { List<spp> sppFound = mspbu.spps.ToList(); if (sppData.name != null) sppFound = sppFound.Where(s => s.name == sppData.name).ToList(); if (sppData.address != null) sppFound = sppFound.Where(s => s.address == sppData.address).ToList(); if (sppData.police_no != null) sppFound = sppFound.Where(s => s.police_no == sppData.police_no).ToList(); if (sppData.shipment_no != null) sppFound = sppFound.Where(s => s.shipment_no == sppData.shipment_no).ToList(); if (sppData.volume != null) sppFound = sppFound.Where(s => s.volume == sppData.volume).ToList(); if (sppData.dens_temp != null) sppFound = sppFound.Where(s => s.dens_temp == sppData.dens_temp).ToList(); if (sppData.buyer != null) sppFound = sppFound.Where(s => s.buyer == sppData.buyer).ToList(); if (sppData.product != null) sppFound = sppFound.Where(s => s.product == sppData.product).ToList(); if (sppData.print_date != null) sppFound = sppFound.Where(s => s.print_date == sppData.print_date).ToList(); if (sppData.verification_date != null) sppFound = sppFound.Where(s => s.verification_date == sppData.verification_date).ToList(); if (sppData.status != null) sppFound = sppFound.Where(s => s.status == sppData.status).ToList(); return sppFound; }