public HttpResponseMessage SaveIssueMasterDetails(object[] data) { InvIssueMaster IssueMaster = JsonConvert.DeserializeObject <InvIssueMaster>(data[0].ToString()); List <InvIssueDetail> IssueDetails = JsonConvert.DeserializeObject <List <InvIssueDetail> >(data[1].ToString()); int menuID = Convert.ToInt16(data[2]); string result = ""; try { if (ModelState.IsValid && IssueMaster != null && IssueDetails.Count > 0 && menuID != null) { result = objIssueService.SaveIssueMasterDetails(IssueMaster, IssueDetails, menuID); } else { result = ""; } } catch (Exception e) { e.ToString(); result = ""; } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public string SaveIssueMasterDetails(InvIssueMaster IssueMaster, List <InvIssueDetail> IssueDetails, int menuID) { GenericFactory_GF_IssueDetail = new InvIssueDetail_GF(); GenericFactory_GF_IssueMaster = new InvIssueMaster_GF(); GenericFactory_EF_IssueMaster = new InvIssueMaster_EF(); GenericFactory_EF_IssueDetail = new InvIssueDetail_EF(); _ctxCmn = new ERP_Entities(); List <InvStockMaster> lstStockMaster = new List <InvStockMaster>(); List <InvIssueDetail> lstIssueDetail = new List <InvIssueDetail>(); string result = ""; if (IssueMaster.IssueID > 0) { int Result = 0; try { var lstInvIssueMaster = GenericFactory_EF_IssueMaster.GetAll().FirstOrDefault(x => x.IssueID == IssueMaster.IssueID); lstInvIssueMaster.UpdateBy = IssueMaster.CreateBy; lstInvIssueMaster.UpdateOn = DateTime.Now; lstInvIssueMaster.UpdatePc = HostService.GetIP(); lstInvIssueMaster.IssueDate = IssueMaster.IssueDate; lstInvIssueMaster.DepartmentID = IssueMaster.DepartmentID; lstInvIssueMaster.Comments = IssueMaster.Comments; result = lstInvIssueMaster.RequisitionNo; foreach (InvIssueDetail ivrd in IssueDetails) { InvIssueDetail objIssueDetail = GenericFactory_EF_IssueDetail.GetAll().FirstOrDefault(x => x.IssueID == IssueMaster.IssueID && x.IssueDetailID == ivrd.IssueDetailID); objIssueDetail.IssueID = IssueMaster.IssueID; objIssueDetail.ItemID = ivrd.ItemID; objIssueDetail.UnitID = (int)ivrd.UnitID; objIssueDetail.LotID = ivrd.LotID == 0 ? null : ivrd.LotID; objIssueDetail.BatchID = ivrd.BatchID == 0 ? null : ivrd.BatchID; objIssueDetail.IssueQty = ivrd.IssueQty; objIssueDetail.UnitPrice = ivrd.UnitPrice == null ? 0 : ivrd.UnitPrice; objIssueDetail.Amount = ivrd.IssueQty * ivrd.UnitPrice == null ? 0 : ivrd.UnitPrice; objIssueDetail.UpdateBy = IssueMaster.CreateBy; objIssueDetail.UpdateOn = DateTime.Now; objIssueDetail.UpdatePc = HostService.GetIP(); lstIssueDetail.Add(objIssueDetail); } if (lstInvIssueMaster != null) { GenericFactory_EF_IssueMaster.Update(lstInvIssueMaster); GenericFactory_EF_IssueMaster.Save(); } // **************Details Transaction Update************************************************ if (lstIssueDetail.Count != 0) { GenericFactory_EF_IssueDetail.UpdateList(lstIssueDetail); GenericFactory_EF_IssueDetail.Save(); } } catch (Exception e) { e.ToString(); Result = 0; } return(result); } else { using (TransactionScope transaction = new TransactionScope()) { try { //...........START new maxId........// long NextId = Convert.ToInt16(GenericFactory_EF_IssueMaster.getMaxID("InvIssueMaster")); long FirstDigit = 0; long OtherDigits = 0; long nextDetailId = Convert.ToInt64(GenericFactory_EF_IssueDetail.getMaxID("InvIssueDetail")); FirstDigit = Convert.ToInt64(nextDetailId.ToString().Substring(0, 1)); OtherDigits = Convert.ToInt64(nextDetailId.ToString().Substring(1, nextDetailId.ToString().Length - 1)); string customCode = ""; string CustomNo = customCode = GenericFactory_EF_IssueMaster.getCustomCode(menuID, Convert.ToDateTime(IssueMaster.IssueDate), IssueMaster.CompanyID, 1, 1); if (customCode != "") { customCode = CustomNo; } else { customCode = NextId.ToString(); } //.........END for custom code............ // IssueMaster.IssueID = NextId; IssueMaster.CreateOn = DateTime.Now; IssueMaster.CreatePc = HostService.GetIP(); IssueMaster.IssueNo = customCode; foreach (InvIssueDetail ivrd in IssueDetails) { InvIssueDetail objIssueDetail = new InvIssueDetail(); objIssueDetail.IssueDetailID = Convert.ToInt64(FirstDigit + "" + OtherDigits); objIssueDetail.IssueID = NextId; objIssueDetail.ItemID = ivrd.ItemID; objIssueDetail.UnitID = ivrd.UnitID; objIssueDetail.LotID = ivrd.LotID == 0 ? null : ivrd.LotID; objIssueDetail.BatchID = ivrd.BatchID == 0 ? null : ivrd.BatchID; objIssueDetail.IssueQty = ivrd.IssueQty; objIssueDetail.UnitPrice = ivrd.UnitPrice; objIssueDetail.Amount = ivrd.Amount; objIssueDetail.CreateBy = IssueMaster.CreateBy; objIssueDetail.CreateOn = DateTime.Now; objIssueDetail.IsDeleted = false; objIssueDetail.CreatePc = HostService.GetIP(); lstIssueDetail.Add(objIssueDetail); OtherDigits++; } _ctxCmn.InvIssueMasters.Add(IssueMaster); //GenericFactory_EF_IssueMaster.Insert(IssueMaster); //GenericFactory_EF_IssueMaster.Save(); //............Update MaxID.................// GenericFactory_EF_IssueMaster.updateMaxID("InvIssueMaster", Convert.ToInt64(NextId)); //............Update CustomCode.............// GenericFactory_EF_IssueMaster.updateCustomCode(menuID, DateTime.Now, IssueMaster.CompanyID, 1, 1); // GenericFactory_EF_IssueDetail.InsertList(lstRequisitionDetail); _ctxCmn.InvIssueDetails.AddRange(lstIssueDetail); //GenericFactory_EF_IssueDetail.Save(); _ctxCmn.SaveChanges(); //............Update MaxID.................// GenericFactory_EF_IssueDetail.updateMaxID("InvIssueDetail", Convert.ToInt64(FirstDigit + "" + (OtherDigits - 1))); transaction.Complete(); result = customCode; } catch (Exception e) { result = ""; } } } return(result); }