public CustomerEnquiryDTO GetCustomerEnquiry(int enquiryId) { CustomerEnquiryDTO dto = new CustomerEnquiryDTO(); try { using (var entity = new ManiMotorsEntities1()) { dto = (from ce in entity.CustomerEnquiries join c in entity.Customers on ce.CustomerID equals c.CustomerID join emp in entity.Employees on ce.SalesExecutive equals emp.EmployeeID join vs in entity.VehicleSalesStatus on ce.VehicleStatusID equals vs.VehicleSalesStatusID join vi1 in entity.VehicleInfoes on ce.Model1 equals vi1.VehicleInfoID into viI1 from viInfo1 in viI1.DefaultIfEmpty() join vi2 in entity.VehicleInfoes on ce.Model2 equals vi2.VehicleInfoID into viI2 from viInfo2 in viI2.DefaultIfEmpty() join vi3 in entity.VehicleInfoes on ce.Model3 equals vi3.VehicleInfoID into viI3 from viInfo3 in viI3.DefaultIfEmpty() where ce.CustomerEnquiryID == enquiryId select new CustomerEnquiryDTO { CustomerEnquiryID = enquiryId, CustomerID = ce.CustomerID, CustomerName = c.Name, ReferenceBy = ce.ReferenceBy, SalesExecutiveName = emp.FirstName, SalesExecutiveId = ce.SalesExecutive, Model1 = ce.Model1, ModelName1 = viInfo1.ModelName, Model2 = ce.Model2, ModelName2 = viInfo2.ModelName, Model3 = ce.Model3, ModelName3 = viInfo3.ModelName, Color = ce.Color, TestDrive = ce.TestDrive, IsExchangeVehicle = ce.ExchangeVehicle, CashorFinance = ce.CashORFinance, CompetitiveModel = ce.CompetitiveModel, VehicleStatusId = ce.VehicleStatusID, VehicleStatusDescription = vs.Description }).FirstOrDefault(); } } catch (Exception ex) { throw ex; } return(dto); }
private void PopulateEnquiry(CustomerEnquiryDTO dto) { txtReferenceBy.Text = dto.ReferenceBy; //Employees ComboboxItem empItem = new ComboboxItem(); empItem.Text = dto.SalesExecutiveName; empItem.Value = dto.SalesExecutiveId; ddlEmployees.Text = empItem.Text; //Model1 if (dto.Model1 != 0) { ComboboxItem model1item = new ComboboxItem(); model1item.Text = dto.ModelName1; model1item.Value = dto.Model1; ddlModel.Text = model1item.Text; } //Color1 ddlColor1.Text = dto.Color; }
public bool SaveCustomerEnquiry(CustomerEnquiryDTO eDTO, CustomerEnquiryFollowupDTO efDTO, int exchangeVehicleId = 0, string mode = "") { var flag = false; try { using (var entities = new ManiMotorsEntities1()) { using (TransactionScope scope = new TransactionScope()) { if (mode != "EDIT") { try { CustomerEnquiry dbEnt = new CustomerEnquiry() { CustomerID = eDTO.CustomerID, ReferenceBy = eDTO.ReferenceBy, CashORFinance = eDTO.CashorFinance, SalesExecutive = eDTO.SalesExecutiveId, Model1 = eDTO.Model1, Model2 = eDTO.Model2, Model3 = eDTO.Model3, Color = eDTO.Color, TestDrive = eDTO.TestDrive, ExchangeVehicle = eDTO.IsExchangeVehicle, CompetitiveModel = eDTO.CompetitiveModel, VehicleStatusID = eDTO.VehicleStatusId, Createdby = eDTO.CreatedBy, CreatedDate = eDTO.CreatedDate, Modifiedby = eDTO.ModifiedBy, ModifiedDate = eDTO.ModifiedDate }; entities.CustomerEnquiries.Add(dbEnt); entities.SaveChanges(); var CustomerEnquiryID = dbEnt.CustomerEnquiryID; var lstCustomer = entities.CustomerEnquiryFollowUps.Where(i => i.CustomerEnquiryID == CustomerEnquiryID); foreach (var followup in lstCustomer) { followup.IsLatest = false; entities.SaveChanges(); } CustomerEnquiryFollowUp dbEntf = new CustomerEnquiryFollowUp() { CustomerID = efDTO.CustomerId, CustomerEnquiryID = CustomerEnquiryID, Description = efDTO.Description, FollowUpDate = efDTO.FollowUpDate, Createdby = eDTO.CreatedBy, CreatedDate = eDTO.CreatedDate, Modifiedby = eDTO.ModifiedBy, ModifiedDate = eDTO.ModifiedDate, IsLatest = true, }; entities.CustomerEnquiryFollowUps.Add(dbEntf); entities.SaveChanges(); if (exchangeVehicleId != 0) { var customerExchange = entities.CustomerExchangeVehicles.FirstOrDefault(ev => ev.CustomerExchangeVehicleID == exchangeVehicleId); customerExchange.CustomerEnquiryID = CustomerEnquiryID; entities.SaveChanges(); } scope.Complete(); } catch (Exception ex) { scope.Dispose(); throw; } } else { try { var ce = entities.CustomerEnquiries.FirstOrDefault(e => e.CustomerEnquiryID == eDTO.CustomerEnquiryID); ce.CustomerID = eDTO.CustomerID; ce.ReferenceBy = eDTO.ReferenceBy; ce.CashORFinance = eDTO.CashorFinance; ce.SalesExecutive = eDTO.SalesExecutiveId; ce.Model1 = eDTO.Model1; ce.Model2 = eDTO.Model2; ce.Model3 = eDTO.Model3; ce.Color = eDTO.Color; ce.TestDrive = eDTO.TestDrive; ce.ExchangeVehicle = eDTO.IsExchangeVehicle; ce.CompetitiveModel = eDTO.CompetitiveModel; ce.VehicleStatusID = eDTO.VehicleStatusId; ce.Createdby = eDTO.CreatedBy; ce.CreatedDate = eDTO.CreatedDate; ce.Modifiedby = eDTO.ModifiedBy; ce.ModifiedDate = eDTO.ModifiedDate; entities.SaveChanges(); var lstCustomer = entities.CustomerEnquiryFollowUps.Where(i => i.CustomerEnquiryID == eDTO.CustomerEnquiryID); foreach (var followup in lstCustomer) { followup.IsLatest = false; entities.SaveChanges(); } CustomerEnquiryFollowUp dbEntf = new CustomerEnquiryFollowUp() { CustomerID = efDTO.CustomerId, CustomerEnquiryID = eDTO.CustomerEnquiryID, Description = efDTO.Description, FollowUpDate = efDTO.FollowUpDate, Createdby = eDTO.CreatedBy, CreatedDate = eDTO.CreatedDate, Modifiedby = eDTO.ModifiedBy, ModifiedDate = eDTO.ModifiedDate, IsLatest = true, }; entities.CustomerEnquiryFollowUps.Add(dbEntf); entities.SaveChanges(); scope.Complete(); } catch (Exception ex) { scope.Dispose(); throw; } } } } flag = true; } catch (Exception ex) { throw ex; } return(flag); }
private void btnSave_Click(object sender, EventArgs e) { if (txtCustomerName.Text == "" || ddlEmployees.SelectedIndex == -1 || ddlModel1.SelectedIndex == -1 || (!rdnTDYes.Checked && !rdnTDNo.Checked) || (!rdnEVYes.Checked && !rdnEVNo.Checked) || (!rdnCash.Checked && !rdnFinance.Checked) || ddlStatus.SelectedIndex == -1 || txtRemarks.Text == "") { MyMessageBox.ShowBox("Please Enter All Mandatory Fields!!!"); return; } //Get ModelId int Model1 = 0; if (ddlModel1.SelectedIndex != -1) { var model1Item = (ComboboxItem)ddlModel1.SelectedItem; Model1 = Convert.ToInt32(model1Item.Value); } int?Model2 = null; if (ddlModel2.SelectedIndex != -1) { var model2Item = (ComboboxItem)ddlModel2.SelectedItem; Model2 = Convert.ToInt32(model2Item.Value); } int?Model3 = null; if (ddlModel3.SelectedIndex != -1) { var model3Item = (ComboboxItem)ddlModel3.SelectedItem; Model3 = Convert.ToInt32(model3Item.Value); } string color = ddlColor.Text; bool testDrive = rdnTDYes.Checked; bool exchangeVehicle = rdnEVYes.Checked; string payment; if (rdnCash.Checked) { payment = "Cash"; } else { payment = "Finance"; } //Get Sales Executive Id int SalesExecutiveId = 0; if (ddlEmployees.SelectedIndex != -1) { var salesItem = (ComboboxItem)ddlEmployees.SelectedItem; SalesExecutiveId = Convert.ToInt32(salesItem.Value); } //Get StatusId int StatusId = 0; if (ddlStatus.SelectedIndex != -1) { var statusitem = (ComboboxItem)ddlStatus.SelectedItem; StatusId = Convert.ToInt32(statusitem.Value); } CustomerEnquiryDTO dto = new CustomerEnquiryDTO() { CustomerID = Convert.ToInt32(txtCustomerId.Text), ReferenceBy = txtReferenceBy.Text, SalesExecutiveId = SalesExecutiveId, Model1 = Model1, Model2 = Model2, Model3 = Model3, Color = color, TestDrive = testDrive, IsExchangeVehicle = exchangeVehicle, CashorFinance = payment, CompetitiveModel = txtCompetitiveModel.Text, VehicleStatusId = StatusId, CreatedBy = GlobalSetup.Userid, CreatedDate = DateTime.Now, ModifiedBy = 1, ModifiedDate = DateTime.Now }; CustomerEnquiryFollowupDTO efdto = new CustomerEnquiryFollowupDTO() { CustomerId = Convert.ToInt32(txtCustomerId.Text), Description = txtRemarks.Text, FollowUpDate = Convert.ToDateTime(dtFollowupDate.Text), CreatedBy = GlobalSetup.Userid, CreatedDate = DateTime.Now, ModifiedBy = 1, ModifiedDate = DateTime.Now }; CustomerBL obj = new CustomerBL(); if (_mode == "EDIT") { dto.CustomerEnquiryID = _enquiryId; } var flag = obj.SaveCustomerEnquiry(dto, efdto, ExchangeVehicleId, _mode); if (flag) { MyMessageBox.ShowBox("Vehicle Enquiry Saved"); Clear(); } else { MyMessageBox.ShowBox("Vehicle Enquiry Failed to Save"); } }