public BranchViewModel SetRecordinEdit(tblCompanyBranchMaster tblBranch) { BranchViewModel branch = new BranchViewModel(); branch.BranchName = tblBranch.BranchName; branch.BranchCode = tblBranch.BranchCode; branch.BranchType = tblBranch.BranchType; branch.DateInception = tblBranch.InceptionDate.ToShortDateString(); branch.RentPeriodAgreed = Convert.ToDateTime(tblBranch.RentPeriodAgreed).ToShortDateString(); branch.DateWEF = Convert.ToDateTime(tblBranch.DateWEF).ToShortDateString(); branch.Address = tblBranch.Address; branch.Pincode = tblBranch.Pincode; branch.ContactPerson = tblBranch.ContactPerson; branch.MobileNo = tblBranch.MobileNo; branch.InTime = tblBranch.InTime; branch.OutTime = tblBranch.OutTime; branch.Status = (short)tblBranch.Status; //ViewBag.PincodeList = new SelectList(dd._context.Mst_PinCode.ToList(), "Pc_Id", "Pc_Desc"); var pincodelist = _context.Mst_PinCode.Select(x => new { PcId = x.Pc_Id, PincodeWithArea = x.Pc_Desc + "(" + x.Pc_AreaName + ")" }).ToList(); //ViewBag.PincodeList = new SelectList(pincodelist, "PcId", "PincodeWithArea"); var pincodemodel = _context.Mst_PinCode.Where(x => x.Pc_Id == branch.Pincode).Select(x => new PincodeViewModel { CityId = x.Pc_CityId, ZoneId = x.Pc_ZoneId, AreaName = x.Pc_AreaName }).FirstOrDefault(); var ZoneName = _context.tblZonemasters.Where(x => x.ZoneID == pincodemodel.ZoneId).Select(x => x.Zone).FirstOrDefault(); var cityname = _context.tblCityMasters.Where(x => x.CityID == pincodemodel.CityId).Select(x => new CityViewModel { CityName = x.CityName, StateId = (int)x.StateID }).FirstOrDefault(); var statename = _context.tblStateMasters.Where(x => x.StateID == cityname.StateId).Select(x => x.StateName).FirstOrDefault(); branch.AreaName = pincodemodel.AreaName; branch.ZoneName = ZoneName; branch.CityName = cityname.CityName; branch.StateName = statename; return(branch); }
public BranchViewModel SetRecordinEdit(tblCompanyBranchMaster tblBranch) { return(_branchRepository.SetRecordinEdit(tblBranch)); }
public void SaveUpdateRecord(BranchViewModel branch) { tblCompanyBranchMaster tblBranch = new tblCompanyBranchMaster(); try { if (branch.ID <= 0) { tblBranch.BranchName = branch.BranchName; tblBranch.BranchCode = branch.BranchCode; tblBranch.BranchType = branch.BranchType; tblBranch.InceptionDate = Convert.ToDateTime(branch.DateInception); if (tblBranch.BranchType == 2) { tblBranch.RentPeriodAgreed = null; } else { tblBranch.RentPeriodAgreed = Convert.ToDateTime(branch.RentPeriodAgreed); } tblBranch.DateWEF = Convert.ToDateTime(branch.DateWEF); tblBranch.Address = branch.Address; tblBranch.Pincode = branch.Pincode; tblBranch.ContactPerson = branch.ContactPerson; tblBranch.MobileNo = branch.MobileNo; tblBranch.InTime = branch.InTime; tblBranch.OutTime = branch.OutTime; tblBranch.Status = branch.Status; tblBranch.RecordCreated = DateTime.Now; tblBranch.RecordCreatedBy = branch.CreatedBy; tblBranch.RecordUpdated = DateTime.Now; tblBranch.RecordUpdatedBy = branch.UpdatedBy; tblBranch.CompID = 1; _context.tblCompanyBranchMasters.Add(tblBranch); } else { tblBranch = _context.tblCompanyBranchMasters.Where(x => x.BID == branch.ID && x.Status == 1).FirstOrDefault(); // first inactive record then insert active record if (tblBranch.InceptionDate != Convert.ToDateTime(branch.DateInception)) { tblBranch.Status = 2; _context.SaveChanges(); tblBranch = new tblCompanyBranchMaster(); tblBranch.BranchName = branch.BranchName; tblBranch.BranchCode = branch.BranchCode; tblBranch.BranchType = branch.BranchType; tblBranch.InceptionDate = Convert.ToDateTime(branch.DateInception); if (tblBranch.BranchType == 2) { tblBranch.RentPeriodAgreed = null; } else { tblBranch.RentPeriodAgreed = Convert.ToDateTime(branch.RentPeriodAgreed); } tblBranch.DateWEF = Convert.ToDateTime(branch.DateWEF); tblBranch.Address = branch.Address; tblBranch.Pincode = branch.Pincode; tblBranch.ContactPerson = branch.ContactPerson; tblBranch.MobileNo = branch.MobileNo; tblBranch.InTime = branch.InTime; tblBranch.OutTime = branch.OutTime; tblBranch.Status = branch.Status; tblBranch.RecordUpdated = DateTime.Now; tblBranch.RecordUpdatedBy = branch.UpdatedBy; tblBranch.RecordCreated = DateTime.Now; tblBranch.RecordCreatedBy = branch.CreatedBy; tblBranch.CompID = 1; _context.tblCompanyBranchMasters.Add(tblBranch); } else { tblBranch.BranchName = branch.BranchName; tblBranch.BranchCode = branch.BranchCode; tblBranch.BranchType = branch.BranchType; tblBranch.InceptionDate = Convert.ToDateTime(branch.DateInception); if (tblBranch.BranchType == 2) { tblBranch.RentPeriodAgreed = null; } else { tblBranch.RentPeriodAgreed = Convert.ToDateTime(branch.RentPeriodAgreed); } //tblBranch.DateWEF = Convert.ToDateTime(branch.DateWEF); tblBranch.Address = branch.Address; tblBranch.Pincode = branch.Pincode; tblBranch.ContactPerson = branch.ContactPerson; tblBranch.MobileNo = branch.MobileNo; tblBranch.InTime = branch.InTime; tblBranch.OutTime = branch.OutTime; tblBranch.Status = branch.Status; tblBranch.RecordUpdated = DateTime.Now; tblBranch.RecordUpdatedBy = branch.UpdatedBy; } } _context.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } }