/// <summary> /// Save the P&L /// </summary> /// <param name="profitlossVO">Value object of P&L</param> public void SaveProfitLoss(ProfitLossVO profitlossVO) { if (profitlossVO.ProfitLossId == 0) { //Insert New Record P_LMapping newProfitLoss = new P_LMapping(); newProfitLoss.CostCentreID = profitlossVO.CostCentreId; newProfitLoss.CompanyID = profitlossVO.CompanyId; newProfitLoss.P_L = profitlossVO.ProfitLossName; newProfitLoss.ID = profitlossVO.ProfitLossId; newProfitLoss.CreationDate = DateTime.Now; newProfitLoss.CreatedBy = profitlossVO.CreatedByUserId; mdbDataContext.P_LMappings.InsertOnSubmit(newProfitLoss); mdbDataContext.SubmitChanges(); } else { //Update Existing Record P_LMapping selectedProfitLoss = mdbDataContext.P_LMappings.SingleOrDefault(c => c.ID == profitlossVO.ProfitLossId); selectedProfitLoss.P_L = profitlossVO.ProfitLossName; selectedProfitLoss.CompanyID = profitlossVO.CompanyId; selectedProfitLoss.CostCentreID = profitlossVO.CostCentreId; selectedProfitLoss.LastUpdatedDate = DateTime.Now; selectedProfitLoss.LastUpdatedBy = profitlossVO.LastUpdatedByUserId; mdbDataContext.SubmitChanges(); } }
/// <summary> /// Transpose LINQ object to Value object /// </summary> /// <param name="profitloss">LINQ profitloss object</param> public ProfitLossVO(P_LMapping profitloss) { ProfitLossId = profitloss.ID; CompanyId = profitloss.CompanyID; CostCentreId = profitloss.CostCentreID; OACostcenterId = profitloss.OACostCentre.CostCentreID; CostCenterName = profitloss.OACostCentre.CostCentreName; ProfitLossName = profitloss.P_L; CreatedByUserId = profitloss.CreatedBy; LastUpdatedByUserId = profitloss.LastUpdatedBy; }
/// <summary> /// Delete Selected P&L /// </summary> /// <param name="Ids">List of ProfitLoss Ids</param> /// <param name="userId">The logged in user id</param> public void DeleteProfitLoss(List <int> Ids, int?userId) { foreach (var id in Ids) { if (id != 0) { P_LMapping deleteProfitLoss = new P_LMapping(); deleteProfitLoss = mdbDataContext.P_LMappings.SingleOrDefault(c => c.ID == id); deleteProfitLoss.IsDeleted = true; deleteProfitLoss.LastUpdatedDate = DateTime.Now; deleteProfitLoss.LastUpdatedBy = userId; mdbDataContext.SubmitChanges(); } } }
/// <summary> /// Gets the Profitloss details by profitloss id. /// </summary> /// <param name="profitlossId">profitlossid</param> /// <returns>Profitloss details</returns> public ProfitLossVO GetPandLbyId(int profitlossId = 0) { P_LMapping profitloss = mdbDataContext.P_LMappings.SingleOrDefault(c => c.ID == profitlossId); ProfitLossVO profitlossVO = null; if (profitloss != null) { profitlossVO = new ProfitLossVO(profitloss); //Set the Costcenter Name OACostCentre costcenter = mdbDataContext.OACostCentres.FirstOrDefault(oac => oac.ID == profitloss.CostCentreID); profitlossVO.CostCenterName = costcenter.CostCentreName; //set the company name OACompany company = mdbDataContext.OACompanies.SingleOrDefault(oac => oac.ID == profitloss.CompanyID); profitlossVO.CompanyName = company.CompanyName; } return(profitlossVO); }
/// <summary> /// Gets the CostCenter by CostCenterId /// </summary> /// <param name="costCentreId">CostCenter Id</param> /// <param name="companyId">Company Id</param> /// <returns>Return value object of P&L</returns> public ProfitLossVO GetCostCenterById(int costCentreId, int companyId) { P_LMapping profitLoss = mdbDataContext.P_LMappings.Where(c => c.CostCentreID == costCentreId && c.CompanyID == companyId && c.IsDeleted == false).SingleOrDefault(); ProfitLossVO selectedProfitLoss = null; if (profitLoss != null) { selectedProfitLoss = new ProfitLossVO(profitLoss); //Set the Costcenter Name OACostCentre costcenter = mdbDataContext.OACostCentres.FirstOrDefault(oac => oac.ID == costCentreId); selectedProfitLoss.CostCenterName = costcenter.CostCentreName; //set the company name OACompany company = mdbDataContext.OACompanies.SingleOrDefault(oac => oac.ID == companyId); selectedProfitLoss.CompanyName = company.CompanyName; } return(selectedProfitLoss); }