public ResponseModel SavePackageRawItem(List <PackageRawItem> models) { var singleModel = new PackageRawItem(); foreach (var item in models) { var existingList = DbContext.PackageRawItem.Where(r => r.RawItemId == item.RawItemId && r.PackageId == item.PackageId).ToList(); if (existingList.Count > 0) { singleModel = existingList.FirstOrDefault(); break; } } if (singleModel.Id == null) { foreach (PackageRawItem model in models) { model.CreatedDate = DateTime.Now; model.Id = Guid.NewGuid().ToString(); DbContext.PackageRawItem.Add(model); DbContext.SaveChanges(); } return(new ResponseModel { Success = true, Message = "Success" }); } return(new ResponseModel { Success = false, Message = DbContext.Package.Where(r => r.Id == singleModel.PackageId).FirstOrDefault().Name + " Has already added on list." }); }
public ResponseModel DeletePackageRawItem(PackageRawItem model) { try { var local = DbContext.Set <PackageRawItem>().Local.FirstOrDefault(c => c.Id == model.Id); if (local != null) { DbContext.Entry(local).State = EntityState.Detached; } DbContext.Entry(model).State = EntityState.Deleted; DbContext.SaveChanges(); } catch (Exception ex) { return(new ResponseModel { Success = false, Message = "Shift can not be delete. Package is using on transaction." }); } return(new ResponseModel { Success = true, Message = "Success" }); }
public IHttpActionResult Delete([FromBody] PackageRawItem model) { return(Ok(_rawItemRepository.DeletePackageRawItem(model))); }