/// <summary> /// Save the profitloss details. /// </summary> /// <param name="model">The ProfitLoss model</param> public ActionResult ProfitLossSave(MODEL.ProfitLoss model) { try { ProfitLossService profitlossService = new ProfitLossService(); if (ModelState.IsValid) { //Get user id int?userId = Session.GetUserId(); //ProfitLossVO profitlossVO = new ProfitLossVO(model, userId); ProfitLossVO profitlossVO = model.Transpose(userId); profitlossService.SaveProfitLoss(profitlossVO); return(new HttpStatusCodeResult(200)); } else { throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.PROFITANDLOSS)); } } catch (ApplicationException e) { return(new HttpStatusCodeAndErrorResult(500, e.Message)); } }
/// <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 profitloss value object to model object /// </summary> public ProfitLoss(ProfitLossVO profitlossVO) { ID = profitlossVO.ProfitLossId; CompanyId = profitlossVO.CompanyId; CostCenterId = profitlossVO.CostCentreId; OACostcenterId = profitlossVO.OACostcenterId; CostCenterName = OACostcenterId + '-' + profitlossVO.CostCenterName; ProfitLossName = profitlossVO.ProfitLossName; CompanyName = profitlossVO.CompanyName; }
/// <summary> /// Transpose Model object to Value Object /// </summary> /// <param name="userId">user Id</param> /// <returns>Value object</returns> public ProfitLossVO Transpose(int?userId) { ProfitLossVO profitLossVO = new ProfitLossVO(); profitLossVO.ProfitLossId = this.ID; profitLossVO.CompanyId = this.CompanyId; profitLossVO.CostCentreId = this.CostCenterId; profitLossVO.OACostcenterId = this.OACostcenterId; profitLossVO.CostCenterName = this.OACostcenterId + '-' + this.CostCenterName; profitLossVO.ProfitLossName = this.ProfitLossName; profitLossVO.CompanyName = this.CompanyName; profitLossVO.CreatedByUserId = userId; profitLossVO.LastUpdatedByUserId = userId; return(profitLossVO); }
/// <summary> /// Save the P&L /// </summary> /// <param name="profitlossVO">Value object of ProfitLoss</param> public void SaveProfitLoss(ProfitLossVO profitlossVO) { if (profitlossVO.CostCentreId > 0) { ProfitLossVO profitLossExist = profitlossDAL.GetCostCenterById(profitlossVO.CostCentreId, profitlossVO.CompanyId); if (profitLossExist != null && profitlossVO.CostCentreId == profitLossExist.CostCentreId && profitlossVO.ProfitLossId == 0) { throw new ApplicationException(String.Format(Constants.COST_CENTRE_ALREADY_MAPPED_WITH_COMPANY, profitLossExist.CostCenterName, profitLossExist.CompanyName)); } else { profitlossDAL.SaveProfitLoss(profitlossVO); } } }
/// <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); }
/// <summary> /// Edit profitloss details by id. /// </summary> /// <param name="id">Profitloss Id</param> /// <returns>The profit loss details view</returns> public ActionResult ProfitLossEdit(int id) { MODEL.ProfitLoss profitloss = new ProfitLoss(); try { ProfitLossService profitlossService = new ProfitLossService(); //Get P&L details ProfitLossVO profitlossVO = profitlossService.GetPandLbyId(id); if (profitlossVO == null) { ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.PROFITANDLOSS)); } else { profitloss = new ProfitLoss(profitlossVO); } } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(PartialView("ProfitLossDetails", profitloss)); }