Example #1
0
        public override void Save()
        {
            try
            {
                var list = (from a in grdCompanyCharges.Rows
                            select new
                {
                    Id = a.Cells[COL_CompanyCharges.Id].Value.ToInt(),

                    MileageId = a.Cells[COL_CompanyCharges.MileageId].Value.ToInt(),
                    Mileage = a.Cells[COL_CompanyCharges.Mileage].Value.ToBool(),

                    FaresId = a.Cells[COL_CompanyCharges.FaresId].Value.ToInt(),
                    Fares = a.Cells[COL_CompanyCharges.Fares].Value.ToBool(),

                    ParkingChargesId = a.Cells[COL_CompanyCharges.ParkingChargesId].Value.ToInt(),
                    ParkingCharges = a.Cells[COL_CompanyCharges.ParkingCharges].Value.ToBool(),

                    WaitingTimeId = a.Cells[COL_CompanyCharges.WaitingTimeId].Value.ToInt(),
                    WaitingTime = a.Cells[COL_CompanyCharges.WaitingTime].Value.ToBool(),

                    PassengerId = a.Cells[COL_CompanyCharges.PassengerId].Value.ToInt(),
                    Passenger = a.Cells[COL_CompanyCharges.Passenger].Value.ToBool(),

                    ExtraChargesId = a.Cells[COL_CompanyCharges.ExtraChargesId].Value.ToInt(),
                    ExtraCharges = a.Cells[COL_CompanyCharges.ExtraCharges].Value.ToBool(),

                    SignatureId = a.Cells[COL_CompanyCharges.SignatureId].Value.ToInt(),
                    Signature = a.Cells[COL_CompanyCharges.Signature].Value.ToBool(),
                }).ToList();

                int CompanyId = 0;
                foreach (var item in list)
                {
                    CompanyId = item.Id;

                    var list2 = list.Where(c => c.Id == CompanyId).ToList();

                    var list3 = (from a in list2
                                 select new
                    {
                        CompanyId = a.Id,
                        MileageId = a.Mileage == true ? a.MileageId.ToIntorNull() : null,
                        FaresId = a.Fares == true ? a.FaresId.ToIntorNull() : null,
                        ExtraChargesId = a.ExtraCharges == true ? a.ExtraChargesId.ToIntorNull() : null,
                        WaitingTimeId = a.WaitingTime == true ? a.WaitingTimeId.ToIntorNull() : null,
                        ParkingChargesId = a.ParkingCharges == true ? a.ParkingChargesId.ToIntorNull() : null,
                        PassengerId = a.Passenger == true ? a.PassengerId.ToIntorNull() : null,
                        SignatureId = a.Signature == true ? a.SignatureId.ToIntorNull() : null,
                    }).ToList();

                    List <Gen_Company_ExtraCharge> objCharges = new List <Gen_Company_ExtraCharge>();

                    foreach (var item3 in list3)
                    {
                        if (item3.MileageId != null)
                        {
                            objCharges.Add(new Gen_Company_ExtraCharge {
                                CompanyId = item3.CompanyId, Charges = item3.MileageId
                            });
                        }
                        if (item3.FaresId != null)
                        {
                            objCharges.Add(new Gen_Company_ExtraCharge {
                                CompanyId = item3.CompanyId, Charges = item3.FaresId
                            });
                        }
                        if (item3.ParkingChargesId != null)
                        {
                            objCharges.Add(new Gen_Company_ExtraCharge {
                                CompanyId = item3.CompanyId, Charges = item3.ParkingChargesId
                            });
                        }
                        if (item3.ExtraChargesId != null)
                        {
                            objCharges.Add(new Gen_Company_ExtraCharge {
                                CompanyId = item3.CompanyId, Charges = item3.ExtraChargesId
                            });
                        }
                        if (item3.WaitingTimeId != null)
                        {
                            objCharges.Add(new Gen_Company_ExtraCharge {
                                CompanyId = item3.CompanyId, Charges = item3.WaitingTimeId
                            });
                        }
                        if (item3.PassengerId != null)
                        {
                            objCharges.Add(new Gen_Company_ExtraCharge {
                                CompanyId = item3.CompanyId, Charges = item3.PassengerId
                            });
                        }
                        if (item3.SignatureId != null)
                        {
                            objCharges.Add(new Gen_Company_ExtraCharge {
                                CompanyId = item3.CompanyId, Charges = item3.SignatureId
                            });
                        }
                    }
                    objMaster.GetByPrimaryKey(CompanyId);
                    objMaster.Edit();
                    string[] skipChargesProperties = { "Gen_Company", "Gen_Charge" };

                    IList <Gen_Company_ExtraCharge> savedChargesList = objMaster.Current.Gen_Company_ExtraCharges;

                    Utils.General.SyncChildCollection(ref savedChargesList, ref objCharges, "Id", skipChargesProperties);
                    objMaster.Save();
                    objMaster.Clear();
                }

                ENUtils.ShowMessage("Account Additional Charges saved successfully.");
            }
            catch (Exception ex)
            {
                if (objMaster.Errors.Count > 0)
                {
                    ENUtils.ShowMessage(objMaster.ShowErrors());
                }
                else
                {
                    ENUtils.ShowMessage(ex.Message);
                }
            }
        }