public int AddAdditionalCharge(AdditionalCharge model)
 {
     using (REMSDBEntities context = new REMSDBEntities())
     {
         try
         {
             context.AdditionalCharges.Add(model);
             int i = context.SaveChanges();
             return(i);
         }
         catch (Exception ex)
         {
             Helper hp = new Helper();
             hp.LogException(ex);
             return(0);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Save Additional Charge
        /// </summary>
        /// <param name="additionalChargeType"></param>
        /// <returns></returns>
        public AdditionalChargeType SaveAdditionalCharge(AdditionalChargeType additionalChargeType)
        {
            AdditionalChargeType additionalChargeTypeDbVersion =
                additionalChargeTypeRepository.Find(additionalChargeType.AdditionalChargeTypeId);

            if (additionalChargeTypeDbVersion == null) //Add Case
            {
                AditionalChargeValidation(additionalChargeType.AdditionalCharges);

                additionalChargeType.IsActive            = true;
                additionalChargeType.IsDeleted           =
                    additionalChargeType.IsPrivate       = additionalChargeType.IsReadOnly = false;
                additionalChargeType.RecLastUpdatedBy    =
                    additionalChargeType.RecCreatedBy    = additionalChargeTypeRepository.LoggedInUserIdentity;
                additionalChargeType.RecCreatedDt        = additionalChargeType.RecLastUpdatedDt = DateTime.Now;
                additionalChargeType.RowVersion          = 0;
                additionalChargeType.AdditionalChargeKey = 0;
                additionalChargeType.UserDomainKey       = additionalChargeTypeRepository.UserDomainKey;

                if (additionalChargeType.AdditionalCharges != null)
                {
                    foreach (var item in additionalChargeType.AdditionalCharges)
                    {
                        item.IsActive         = true;
                        item.IsDeleted        = item.IsPrivate = item.IsReadOnly = false;
                        item.RecLastUpdatedBy = item.RecCreatedBy = additionalChargeTypeRepository.LoggedInUserIdentity;
                        item.RecCreatedDt     = item.RecLastUpdatedDt = DateTime.Now;
                        item.RowVersion       = 0;
                        item.RevisionNumber   = 0;
                        item.UserDomainKey    = additionalChargeTypeRepository.UserDomainKey;
                    }
                }
                additionalChargeTypeRepository.Add(additionalChargeType);
                additionalChargeTypeRepository.SaveChanges();
            }
            else //Update Case
            {
                additionalChargeTypeDbVersion.RecLastUpdatedBy = additionalChargeTypeRepository.LoggedInUserIdentity;
                additionalChargeTypeDbVersion.RecLastUpdatedDt = DateTime.Now;
                additionalChargeTypeDbVersion.IsEditable       = additionalChargeType.IsEditable;

                foreach (var item in additionalChargeType.AdditionalCharges)
                {
                    if (
                        additionalChargeTypeDbVersion.AdditionalCharges.All(
                            x =>
                            x.AdditionalChargeId != item.AdditionalChargeId ||
                            item.AdditionalChargeId == 0))
                    {
                        item.IsActive         = true;
                        item.IsDeleted        = item.IsPrivate = item.IsReadOnly = false;
                        item.RecLastUpdatedBy = item.RecCreatedBy = additionalChargeTypeRepository.LoggedInUserIdentity;
                        item.RecCreatedDt     = item.RecLastUpdatedDt = DateTime.Now;
                        item.RowVersion       = 0;
                        item.RevisionNumber   = 0;
                        item.UserDomainKey    = additionalChargeTypeRepository.UserDomainKey;
                        additionalChargeTypeDbVersion.AdditionalCharges.Add(item);
                    }
                    else
                    {
                        if (additionalChargeTypeDbVersion.AdditionalCharges.Any(
                                x =>
                                x.AdditionalChargeId == item.AdditionalChargeId))
                        {
                            AdditionalCharge additionalChargeDbVesion =
                                additionalChargeTypeDbVersion.AdditionalCharges.First(
                                    x => x.AdditionalChargeId == item.AdditionalChargeId);
                            if (additionalChargeDbVesion.HireGroupDetailId != item.HireGroupDetailId ||
                                additionalChargeDbVesion.StartDt != item.StartDt ||
                                additionalChargeDbVesion.AdditionalChargeRate != item.AdditionalChargeRate)
                            {
                                item.IsActive               = true;
                                item.IsDeleted              = item.IsPrivate = item.IsReadOnly = false;
                                item.RecLastUpdatedBy       =
                                    item.RecCreatedBy       = additionalChargeTypeRepository.LoggedInUserIdentity;
                                item.RecCreatedDt           = item.RecLastUpdatedDt = DateTime.Now;
                                item.RowVersion             = 0;
                                item.AdditionalChargeTypeId = additionalChargeType.AdditionalChargeTypeId;
                                item.RevisionNumber         = additionalChargeDbVesion.RevisionNumber + 1;
                                item.AdditionalChargeId     = 0;
                                item.UserDomainKey          = additionalChargeTypeRepository.UserDomainKey;
                                additionalChargeRepository.Add(item);
                                additionalChargeRepository.SaveChanges();
                                additionalChargeDbVesion.ChildAdditionalChargeId = item.AdditionalChargeId;
                            }
                        }
                    }
                }
            }



            additionalChargeTypeRepository.SaveChanges();

            return(new AdditionalChargeType
            {
                AdditionalChargeTypeId = additionalChargeType.AdditionalChargeTypeId,
                AdditionalChargeTypeCode = additionalChargeType.AdditionalChargeTypeCode,
                AdditionalChargeTypeName = additionalChargeType.AdditionalChargeTypeName,
                AdditionalChargeTypeDescription = additionalChargeType.AdditionalChargeTypeDescription,
                IsEditable = additionalChargeType.IsEditable,
            });
        }
예제 #3
0
        //public FlatDetailModel GetFlatDetails(int FlatID)
        //{
        //    REMSDBEntities context = new REMSDBEntities();
        //    var flmodel = context.Flats.Where(fl => fl.FlatID == FlatID).FirstOrDefault();
        //    Mapper.CreateMap<Flat, FlatDetailModel>();
        //    FlatDetailModel model = new FlatDetailModel();
        //    model = Mapper.Map<Flat, FlatDetailModel>(flmodel);
        //    var flor = context.Floors.Where(fl => fl.FloorID == model.FloorID).FirstOrDefault();
        //    model.FloorName = flor.FloorName;
        //    model.FloorNo = flor.FloorNo;
        //    var twr = context.Towers.Where(tw => tw.TowerID == flor.TowerID).FirstOrDefault();
        //    model.TowerID = twr.TowerID;
        //    model.TowerName = twr.TowerName;
        //    model.TowerNo = twr.TowerNo;
        //    model.Block = twr.Block;
        //    var fmodel = context.FlatPLCs.Where(pl => pl.FlatID == FlatID).ToList();
        //    List<FlatPLCModel> FlatPLCList = new List<FlatPLCModel>();
        //    foreach (FlatPLC fp in fmodel)
        //    {
        //        Mapper.CreateMap<FlatPLC, FlatPLCModel>();
        //        var fpm = Mapper.Map<FlatPLC, FlatPLCModel>(fp);
        //        fpm.PLCName = fp.PLC.PLCName;
        //        fpm.AmountSqFt = fp.PLC.AmountSqFt;
        //        fpm.TotalAmount = fp.PLC.AmountSqFt * model.FlatSize;
        //        FlatPLCList.Add(fpm);
        //    }
        //    model.FlatPLCList = FlatPLCList;
        //    var amodel = context.FlatCharges.Where(fc => fc.FlatID == FlatID).ToList();
        //    List<FlatChargeModel> FlatChargeList = new List<FlatChargeModel>();
        //    foreach (var ac in amodel)
        //    {
        //        Mapper.CreateMap<FlatCharge, FlatChargeModel>();
        //        var acmodel = Mapper.Map<FlatCharge, FlatChargeModel>(ac);
        //        acmodel.ChargeName = ac.AdditionalCharge.Name;
        //        acmodel.Amount = ac.AdditionalCharge.Amount;
        //        acmodel.ChargeType = ac.AdditionalCharge.ChargeType;
        //        if (acmodel.ChargeType == "Free")
        //        {
        //            acmodel.TotalAmount = 0;
        //        }
        //        else if (acmodel.ChargeType == "Sq. Ft.")
        //        {
        //            acmodel.TotalAmount = ac.AdditionalCharge.Amount * model.FlatSize;
        //        }
        //        else if (acmodel.ChargeType == "One Time")
        //        {
        //            acmodel.TotalAmount = ac.AdditionalCharge.Amount;
        //        }
        //        FlatChargeList.Add(acmodel);
        //    }
        //    model.FlatChargeList = FlatChargeList;
        //    return model;
        //}

        public FlatDetailModel GetFlatDetails(int FlatID)
        {
            REMSDBEntities context = new REMSDBEntities();
            var            flmodel = context.Flats.Where(fl => fl.FlatID == FlatID).FirstOrDefault();

            Mapper.CreateMap <Flat, FlatDetailModel>();
            FlatDetailModel model = new FlatDetailModel();

            model = Mapper.Map <Flat, FlatDetailModel>(flmodel);
            var flor = context.Floors.Where(fl => fl.FloorID == model.FloorID).FirstOrDefault();

            model.FloorName = flor.FloorName;
            model.FloorNo   = flor.FloorNo;
            var twr = context.Towers.Where(tw => tw.TowerID == flor.TowerID).FirstOrDefault();

            model.TowerID   = twr.TowerID;
            model.TowerName = twr.TowerName;
            model.TowerNo   = twr.TowerNo;
            model.Block     = twr.Block;
            var fmodel = context.FlatPLCs.Where(pl => pl.FlatID == FlatID).ToList();
            List <FlatPLCModel> FlatPLCList = new List <FlatPLCModel>();

            foreach (FlatPLC fp in fmodel)
            {
                Mapper.CreateMap <FlatPLC, FlatPLCModel>();
                var fpm = Mapper.Map <FlatPLC, FlatPLCModel>(fp);
                fpm.PLCName     = fp.PLC.PLCName;
                fpm.AmountSqFt  = fp.PLC.AmountSqFt;
                fpm.TotalAmount = fp.PLC.AmountSqFt * model.FlatSize;
                FlatPLCList.Add(fpm);
            }
            model.FlatPLCList = FlatPLCList;
            var amodel = context.FlatCharges.Where(fc => fc.FlatID == FlatID).ToList();
            List <FlatChargeModel> FlatChargeList = new List <FlatChargeModel>();

            foreach (var ac in amodel)
            {
                Mapper.CreateMap <FlatCharge, FlatChargeModel>();
                var acmodel = Mapper.Map <FlatCharge, FlatChargeModel>(ac);
                acmodel.ChargeName = ac.AdditionalCharge.Name;
                acmodel.Amount     = ac.AdditionalCharge.Amount;
                acmodel.ChargeType = ac.AdditionalCharge.ChargeType;
                if (acmodel.ChargeType == "Free")
                {
                    acmodel.TotalAmount = 0;
                }
                else if (acmodel.ChargeType == "Sq. Ft.")
                {
                    acmodel.TotalAmount = ac.AdditionalCharge.Amount * model.FlatSize;
                }
                else if (acmodel.ChargeType == "One Time")
                {
                    acmodel.TotalAmount = ac.AdditionalCharge.Amount;
                }
                FlatChargeList.Add(acmodel);
            }
            model.FlatPlanCharge = context.Rem_GetFlatPlanCharge(FlatID).ToList();
            model.FloorWisePlc   = context.PLCs.Where(p => p.FloorNo == model.FloorNo).ToList();
            model.FlatChargeList = FlatChargeList;
            List <AdditionalCharge> AdditionalCharge = new List <AdditionalCharge>();
            var q = context.AdditionalCharges.ToList();

            for (int i = 0; i < q.Count - 1; i++)
            {
                AdditionalCharge additionalCharge = new AdditionalCharge();
                additionalCharge.ChargeType = q[i].ChargeType;
                additionalCharge.Amount     = q[i].Amount;
                additionalCharge.Name       = q[i].Name;
                if (additionalCharge.ChargeType == "Free")
                {
                    additionalCharge.Amount = 0;
                }
                else if (additionalCharge.ChargeType == "Sq. Ft.")
                {
                    additionalCharge.Amount = q[i].Amount * model.FlatSize;
                }
                else if (additionalCharge.ChargeType == "One Time")
                {
                    additionalCharge.Amount = q[i].Amount;
                }
                AdditionalCharge.Add(additionalCharge);
            }
            model.AdditionalCharge = AdditionalCharge;
            return(model);
        }