public HttpResponseMessage SaveCustomCode(object[] data) { CmnCustomCode itemMaster = JsonConvert.DeserializeObject <CmnCustomCode>(data[0].ToString()); List <CmnCustomCodeDetail> itemDetails = JsonConvert.DeserializeObject <List <CmnCustomCodeDetail> >(data[1].ToString()); CmnCustomCode obj = new CmnCustomCode(); string result = ""; try { result = "1"; if (ModelState.IsValid) { using (CmnCustomCodeMgt objService = new CmnCustomCodeMgt()) { result = (objService.SavCustomCode(itemMaster, itemDetails)).ToString(); } } } catch (Exception e) { e.ToString(); result = e.ToString(); } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
/// <summary> /// Save Data To Database /// <para>Use it when save data through a stored procedure</para> /// </summary> public int SaveCompany(CmnCompany model) { GenericFactoryEF_Company = new CmnCompany_EF(); GFactory_EF_CmnCustomCode = new SalCmnCustomCode_EF(); int result = 0; try { #region CustomCode And Primary Key Process int NextId = Convert.ToInt16(GenericFactoryEF_Company.getMaxID("CmnCompany")); model.CompanyID = NextId; //......... START for custom code........... // //string customCode = ""; CmnCustomCode objCustomCode = GFactory_EF_CmnCustomCode.FindBy(m => m.MenuID == model.MenuID && m.IsDeleted == false).FirstOrDefault(); //int customCodeID = Convert.ToInt16(objCustomCode.RecordID); //if (customCodeID > 0) //{ // // customCode = GenericFactory_EF_SalPIMaster.getCustomCode(customCodeID, DateTime.Now, itemMaster.CompanyID, 1, 1); // customCode = GFactory_EF_CmnCustomCode.getCustomCode(customCodeID, DateTime.Now, 0, 1, 1); //} //else //{ // customCode = NextId.ToString(); //} //.........END for custom code............ // #endregion CustomCode And Primary Key Process Hashtable ht = new Hashtable(); ht.Add("CompanyID", model.CompanyID); ht.Add("CustomCode", model.CustomCode); ht.Add("CompanyShortName", model.CompanyShortName); ht.Add("CompanyName", model.CompanyName); //ht.Add("StatusID", model.StatusID); string spQuery = "[Set_CmnCompany]"; result = GenericFactoryFor_Company.ExecuteCommand(spQuery, ht); //Update Primary Key and Custom Code GenericFactoryEF_Company.updateMaxID("CmnCompany", Convert.ToInt64(NextId)); //GFactory_EF_CmnCustomCode.updateCustomCode(customCodeID, DateTime.Now, 0, 1, 1); } catch (Exception ex) { ErrorLog.Log(ex); ex.ToString(); } return(result); }
public HttpResponseMessage DeleteMaster(int RecordID) { CmnCustomCode itemMaster = new CmnCustomCode(); int result = 0; try { if (ModelState.IsValid) { objService = new CmnCustomCodeMgt(); result = (objService.UpdateMasterStatus(RecordID)); result = 1; } } catch (Exception e) { e.ToString(); result = 0; } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public int SavCustomCode(CmnCustomCode model, List <CmnCustomCodeDetail> details) { GenericFactory_EF_customCode = new CmnCustomCode_EF(); GenericFactory_EF_customDetails = new CmnCustomCodeDetail_EF(); int masterID = model.RecordID; CmnCustomCode modelBase = new CmnCustomCode(); List <Int32> UpdatedIDs = new List <Int32>(); List <CmnCustomCodeDetail> detailsListDeleted = new List <CmnCustomCodeDetail>(); List <CmnCustomCodeDetail> detailsList = new List <CmnCustomCodeDetail>(); List <CmnCustomCodeDetail> detailsInsertionList = new List <CmnCustomCodeDetail>(); int result = 0; try { modelBase = ModelBinding(model, details); foreach (var item in modelBase.CmnCustomCodeDetails) { if (item.EntryStateStatus == "Modified") { CmnCustomCodeDetail detailsEntity = new CmnCustomCodeDetail(); detailsEntity = DetailsBinding(modelBase.CmnCustomCodeDetails.Where(x => x.RecordDetailID == item.RecordDetailID).FirstOrDefault()); detailsList.Add(detailsEntity); UpdatedIDs.Add(detailsEntity.RecordDetailID); } if (item.EntryStateStatus == "Add" && masterID > 0) { CmnCustomCodeDetail detailsEntity = new CmnCustomCodeDetail(); detailsEntity = DetailsBinding(modelBase.CmnCustomCodeDetails.Where(x => x.RecordDetailID == item.RecordDetailID).FirstOrDefault()); detailsInsertionList.Add(detailsEntity); } } foreach (var item in UpdatedIDs) { modelBase.CmnCustomCodeDetails.Remove(modelBase.CmnCustomCodeDetails.Where(x => x.RecordDetailID == item).FirstOrDefault()); } if (masterID == 0) { GenericFactory_EF_customCode.Insert(modelBase); GenericFactory_EF_customCode.Save(); } else { GenericFactory_EF_customCode.Update(model); GenericFactory_EF_customDetails.UpdateList(detailsList); foreach (CmnCustomCodeDetail item in detailsList) { if (item.IsDeleted) { detailsListDeleted.Add(item); } } if (detailsListDeleted.Count > 0) { GenericFactory_EF_customDetails.DeleteList(detailsListDeleted); } GenericFactory_EF_customDetails.InsertList(detailsInsertionList); GenericFactory_EF_customCode.Save(); GenericFactory_EF_customDetails.Save(); GenericFactory_EF_customDetails = new CmnCustomCodeDetail_EF(); } result = 1; } catch (Exception ex) { ex.ToString(); return(result); } return(result); }
private CmnCustomCode ModelBinding(CmnCustomCode model, List <CmnCustomCodeDetail> details) { GenericFactory_EF_customCode = new CmnCustomCode_EF(); try { int NextID = GenericFactory_EF_customCode.getMaxVal_int("RecordID", "CmnCustomCode"); model.RecordID = model.RecordID == 0 ? NextID : model.RecordID; model.CustomCode = model.RecordID.ToString(); model.CompanyID = model.CompanyID; model.IsCompany = model.IsCompany ?? false; model.IsOrganogramCode = model.IsOrganogramCode ?? false; model.IsDeleted = false; NextID = GenericFactory_EF_customCode.getMaxVal_int("RecordDetailID", "CmnCustomCodeDetail"); foreach (CmnCustomCodeDetail Item in details) { CmnCustomCodeDetail entity = new CmnCustomCodeDetail(); entity.RecordDetailID = Item.RecordDetailID; if (Item.RecordDetailID == 0) { if (Item.IsDeleted) { continue; } Item.RecordDetailID = NextID++; entity.RecordDetailID = Item.RecordDetailID; entity.EntryStateStatus = "Add"; } else if (Item.IsDeleted == true) { entity.EntryStateStatus = "Delete"; } else { entity.EntryStateStatus = "Modified"; } entity.CustomCode = entity.RecordDetailID.ToString(); entity.CustomCodeID = model.RecordID; entity.ParameterName = Item.ParameterName; entity.Length = Item.Length; entity.Seperator = Item.Seperator; entity.Sequence = Item.Sequence; entity.StatusID = Item.StatusID; entity.CompanyID = model.CompanyID; entity.CreateBy = Item.CreateBy; entity.CreateOn = Item.CreateOn; entity.CreatePc = Item.CreatePc; entity.UpdateBy = Item.UpdateBy; entity.UpdateOn = Item.UpdateOn; entity.UpdatePc = Item.UpdatePc; if (entity.EntryStateStatus != "Delete") { entity.IsDeleted = false; } else { entity.EntryStateStatus = "Modified"; entity.IsDeleted = true; } entity.DeleteBy = Item.DeleteBy; entity.DeleteOn = Item.DeleteOn; entity.DeletePc = Item.DeletePc; model.CmnCustomCodeDetails.Add(entity); } } catch (Exception ex) { ex.ToString(); } return(model); }
/// <summary> /// Save Data To Database /// <para>Use it when save data through a stored procedure</para> /// </summary> public int SaveCompanyParam(CmnCompany model, UserCommonEntity commonEntity) { GenericFactoryFor_Company = new CmnCompany_GF(); GenericFactoryEF_Company = new CmnCompany_EF(); GFactory_EF_CmnCustomCode = new SalCmnCustomCode_EF(); int result = 0; try { #region CustomCode And Primary Key Process int NextId = Convert.ToInt16(GenericFactoryEF_Company.getMaxID("CmnCompany")); model.CompanyID = NextId; //......... START for custom code........... // //string customCode = ""; CmnCustomCode objCustomCode = GFactory_EF_CmnCustomCode.FindBy(m => m.MenuID == model.MenuID && m.IsDeleted == false).FirstOrDefault(); //int customCodeID = Convert.ToInt16(objCustomCode.RecordID); //if (customCodeID > 0) //{ // // customCode = GenericFactory_EF_SalPIMaster.getCustomCode(customCodeID, DateTime.Now, itemMaster.CompanyID, 1, 1); // customCode = GFactory_EF_CmnCustomCode.getCustomCode(customCodeID, DateTime.Now, 0, 1, 1); //} //else //{ // customCode = NextId.ToString(); //} //.........END for custom code............ // #endregion CustomCode And Primary Key Process #region Basic Save Hashtable ht = new Hashtable(); ht.Add("CompanyID", model.CompanyID); ht.Add("CustomCode", model.CustomCode); ht.Add("CompanyShortName", model.CompanyShortName); ht.Add("CompanyName", model.CompanyName); ht.Add("LoggedCompanyID", commonEntity.loggedCompnyID); ht.Add("LoggedUser", commonEntity.loggedUserID); // ht.Add("StatusID", model.StatusID); string spQuery = "[Set_CmnCompany]"; result = GenericFactoryFor_Company.ExecuteCommand(spQuery, ht); #endregion Basic Save #region WorkFlow Transaction Entry //// CHECK WorkFLow Setup ////IF targetUserID=0 Then Work flow is not configured //int targetUserID = new WorkFLowMgt().GetWorkFlowBeginner(commonEntity); //if (targetUserID > 0) //{ // //IN CASE OF SAVE // //REQUIRD MENUID, COMPANYID, TARGET USERID AS TARGET USERID, USER AS CURRENT USERID,TRANSACTION ID AS MASTERID(INSERTED) ,STATUSID 1 // //IS APPROVED 0, IS DELETE 0, IS UPDATE 0 , @APPROVALCUSTOMCODE = '',Is Declained=0 // var comment = ""; // var APPROVALCUSTOMCODE = string.Empty; // // int WorkFlowStatus = new WorkFLowMgt().ExecuteWorkFlowTransactionProcess(new WorkFLowMgt().SetProcedureParam(commonEntity, targetUserID, NextId, 0, comment, 0, 0, 1, "", 0)); // String MessageName = System.Enum.GetName(typeof(workFlowTranEnum_MessageName), (int)workFlowTranEnum_MessageName.Created); // int WorkFlowStatus = new WorkFLowMgt().ExecuteWorkFlowTransactionProcess(new WorkFLowMgt().SetProcedureParam(commonEntity, targetUserID, NextId, (int)workFlowTranEnum_IsApproved.False, comment, (int)workFlowTranEnum_IsUpdate.False, (int)workFlowTranEnum_IsDelete.False, (int)workFlowTranEnum_Status.Active, APPROVALCUSTOMCODE, (int)workFlowTranEnum_IsDeclained.False, MessageName)); //} #endregion WorkFlow Transaction Entry #region CustomCode And Primary Key Process Update Process //Update Primary Key and Custom Code GenericFactoryEF_Company.updateMaxID("CmnCompany", Convert.ToInt64(NextId)); // GFactory_EF_CmnCustomCode.updateCustomCode(customCodeID, DateTime.Now, 0, 1, 1); #endregion CustomCode And Primary Key Process Update Process #region WorkFlow Transaction Entry Team int workflowID = 0; List <vmCmnWorkFlowMaster> listWorkFlow = new WorkFLowMgt().GetWorkFlowMasterListByMenu(commonEntity); foreach (vmCmnWorkFlowMaster item in listWorkFlow) { int userTeamID = item.UserTeamID ?? 0; if (new WorkFLowMgt().checkUserValidation(commonEntity.loggedUserID ?? 0, item.WorkFlowID) && userTeamID > 0) { item.WorkFlowTranCustomID = model.CompanyID; workflowID = new WorkFLowMgt().ExecuteTransactionProcess(item, commonEntity); //Mail Service } if (userTeamID == 0) { item.WorkFlowTranCustomID = model.CompanyID; workflowID = new WorkFLowMgt().ExecuteTransactionProcess(item, commonEntity); } } #endregion Workflow Transaction Enltry Team } catch (Exception) { throw new Exception(); } return(result); }