public bool UpdateExistingItem(UpdateItemModel item) { Item editItem = new Item(); ItemDetailMapping singleDetail = new ItemDetailMapping(); ItemSingleModel result = new ItemSingleModel(); bool updateDetailMapping = false; var brandName = _itemDataAccess.GetBrandByName(item.BrandName); var codeDetail = _itemDataAccess.GetAllItemStatus(); editItem.Id = item.Id; editItem.ItemName = item.ItemName; editItem.CategoryID = item.CategoryId; editItem.SubCategoryID = item.SubCategoryId; editItem.LocationID = item.LocationId; editItem.BrandID = brandName.Id; editItem.Quantity = item.Quantity; editItem.MeasuredBy = item.MeasuredBy; editItem.ThresholdQty = item.ThresholdQty; editItem.WarningThresholdQty = item.WarningThresholdQty; editItem.Notes = item.Notes; editItem.Sku = item.Sku; editItem.UpdateUserName = "******"; editItem.UpdateDttm = DateTime.UtcNow; editItem.UnitPrice = (decimal)item.UnitPrice; editItem.RetailPrice = (decimal)item.RetailPrice; for (int i = 0; i < item.ItemDetail.Count; i++) { singleDetail.Id = item.ItemDetail[i].Id; singleDetail.ItemID = item.Id; singleDetail.ItemDetailID = item.ItemDetail[i].ItemDetailId; singleDetail.ItemDetailValue = item.ItemDetail[i].ItemDetailValue; singleDetail.IsActive = true; singleDetail.UpdateUserName = "******"; singleDetail.UpdateDttm = DateTime.Now; updateDetailMapping = _itemDataAccess.UpdateItemDetailMappingByItemId(singleDetail); if (!updateDetailMapping) { break; } } var updateItem = _itemDataAccess.UpdateItemById(editItem); if (updateItem && updateDetailMapping) { return(true); } return(false); }
public bool UpdateItemDetailMappingByItemId(ItemDetailMapping item) { using (OrmocIMSEntities context = new OrmocIMSEntities()) { int result = 0; int itemDetailMappingId = item.Id; var query = context.ItemDetailMappings.Where(x => x.Id == itemDetailMappingId).FirstOrDefault(); query.ItemDetailValue = item.ItemDetailValue; query.IsActive = item.IsActive; query.UpdateUserName = item.UpdateUserName; query.UpdateDttm = item.UpdateDttm; context.Entry(query).State = EntityState.Modified; result = result + context.SaveChanges(); return(result > 0 ? true : false); } }
public ItemSingleModel InsertNewItem(InsertItemModel item) { Item newItem = new Item(); List <ItemDetailMapping> detail = new List <ItemDetailMapping>(); ItemDetailMapping singleDetail = new ItemDetailMapping(); ItemSingleModel result = new ItemSingleModel(); var brandName = _itemDataAccess.GetBrandByName(item.BrandName); var codeDetail = _itemDataAccess.GetAllItemStatus(); newItem.ItemName = item.ItemName; newItem.CategoryID = item.CategoryId; newItem.SubCategoryID = item.SubCategoryId; newItem.StatusCd = codeDetail.Where(x => x.CodeValue.Equals("Active")).Select(x => x.Id).FirstOrDefault(); newItem.LocationID = item.LocationId; newItem.BrandID = brandName.Id; newItem.Quantity = item.Quantity; newItem.MeasuredBy = item.MeasuredBy; newItem.ThresholdQty = item.ThresholdQty; newItem.WarningThresholdQty = item.WarningThresholdQty; newItem.Notes = item.Notes; newItem.Sku = item.Sku; newItem.CreateUserName = "******"; newItem.CreateDttm = DateTime.UtcNow; newItem.UpdateUserName = "******"; newItem.UpdateDttm = DateTime.UtcNow; var insertedItem = _itemDataAccess.InsertNewItem(newItem); if (insertedItem != null) { for (int i = 0; i < item.ItemDetail.Count; i++) { singleDetail.ItemDetailID = item.ItemDetail[i].ItemDetailId; singleDetail.ItemDetailValue = item.ItemDetail[i].ItemDetailValue; singleDetail.ItemID = insertedItem.Id; singleDetail.IsActive = true; singleDetail.CreateUserName = "******"; singleDetail.CreateDttm = DateTime.UtcNow; singleDetail.UpdateUserName = "******"; singleDetail.UpdateDttm = DateTime.Now; detail.Add(singleDetail); singleDetail = new ItemDetailMapping(); } var insertedDetail = _itemDataAccess.InsertNewItemDetailMapping(detail); result.Id = insertedItem.Id; result.ItemName = insertedItem.ItemName; result.CategoryId = insertedItem.CategoryID; result.SubCategoryId = insertedItem.SubCategoryID; result.BrandName = item.BrandName; result.LocationId = insertedItem.LocationID; result.Quantity = insertedItem.Quantity.HasValue ? insertedItem.Quantity.Value : 0; result.ThresholdQty = insertedItem.ThresholdQty.HasValue ? insertedItem.ThresholdQty.Value : 0; result.WarningThresholdQty = insertedItem.WarningThresholdQty.HasValue ? insertedItem.WarningThresholdQty.Value : 0; result.MeasuredBy = insertedItem.MeasuredBy; result.Sku = insertedItem.Sku; result.Notes = insertedItem.Notes; result.StatusCd = codeDetail.Where(x => x.Id == insertedItem.StatusCd).Select(x => x.CodeValue).FirstOrDefault(); result.CreateUserName = insertedItem.CreateUserName; result.CreateDttm = insertedItem.CreateDttm; result.UpdateUserName = insertedItem.UpdateUserName; result.UpdateDttm = insertedItem.UpdateDttm; if (insertedDetail) { return(result); } } return(new ItemSingleModel()); }