Exemple #1
0
        public Task Create(int totalParkings, long?floorId, long?facilityId)
        {
            var taskResult = Task.Run(() =>
            {
                using (var context = new DbContext())
                {
                    for (int i = 0; i < totalParkings; i++)
                    {
                        var flatParking  = new FlatParking();
                        flatParking.Name = string.Format("{0}-{1}", "P ", i + 1);

                        if (floorId.HasValue)
                        {
                            flatParking.FloorId = floorId.Value;
                        }

                        if (facilityId.HasValue)
                        {
                            flatParking.FacilityId = facilityId.Value;
                        }

                        context.FlatParkings.Add(flatParking);
                    }
                    context.SaveChanges();
                }
            });

            return(taskResult);
        }
Exemple #2
0
        public Task Update(FlatParking flatParking)
        {
            var taskResult = Task.Run(() =>
            {
                using (var context = new DbContext())
                {
                    var existingRecord = context.FlatParkings.FirstOrDefault(p => p.Id == flatParking.Id);
                    if (existingRecord == null)
                    {
                        throw new Exception("Flat Parking not found");
                    }

                    existingRecord.Name      = flatParking.Name;
                    existingRecord.SqftArea  = flatParking.SqftArea;
                    existingRecord.Type      = flatParking.Type;
                    existingRecord.ParkingNo = flatParking.ParkingNo;

                    context.SaveChanges();
                }
            });

            return(taskResult);
        }
 public Task Update(FlatParking flatParking)
 {
     return(_flatParkingRepository.Update(flatParking));
 }
 public Task <FlatParking> Create(FlatParking flatParking, int?count)
 {
     return(_flatParkingRepository.Create(flatParking, count));
 }
        public Task <Facility[]> Create(Facility[] facilities, long?societyId)
        {
            var taskResult = Task.Run(async() =>
            {
                using (var context = new DbContext())
                {
                    foreach (var facility in facilities)
                    {
                        if (facility.Complex != null)
                        {
                            facility.ComplexId = facility.Complex.Id;
                            facility.Complex   = null;
                        }

                        if (context.Facilities.Any(f => f.Name == facility.Name && f.Wing == facility.Wing && f.ComplexId == facility.ComplexId))
                        {
                            throw new Exception("Facility with same name found in the complex");
                        }

                        if (facility.Type == (byte)EnFacilityType.RowHouses)
                        {
                            //Row Houses

                            //isWing = false;
                            //isNoOfFloors = false;
                            //isNoOfFlats = true;
                            //isNoOfLifts = false;
                            //isNoOfParkinglots = false;
                        }
                        else if (facility.Type == (byte)EnFacilityType.ParkingTower)
                        {
                            //Parking Tower
                            //isWing = true;
                            //isNoOfFloors = true;
                            //isNoOfFlats = false;
                            //isNoOfLifts = true;
                            //isNoOfParkinglots = true;

                            facility.IsParkingLot = true;

                            context.Facilities.Add(facility);
                            context.SaveChanges();

                            int parkingsPerFloor = facility.NoOfParkinglots / facility.NoOfFloors;

                            for (int j = 0; j < facility.NoOfFloors + 1; j++)
                            {
                                //add Floor
                                var floor = new Floor()
                                {
                                    Name        = (j == 0 ? "Ground Floor" : "Floor " + j.ToString()),
                                    FloorNumber = j,
                                    FacilityId  = facility.Id,
                                    Type        = (byte)EnFloorType.Parkings
                                };

                                context.Floors.Add(floor);
                                context.SaveChanges();

                                if (parkingsPerFloor > 0)
                                {
                                    var flatParking = new FlatParking()
                                    {
                                        Facility = new Facility()
                                        {
                                            Id = facility.Id
                                        },
                                    };

                                    await flatParkingRepository.Create(flatParking, parkingsPerFloor);
                                }
                            }

                            if (facility.NoOfLifts > 0)
                            {
                                for (int i = 1; i <= facility.NoOfLifts; i++)
                                {
                                    context.SocietyAssets.Add(new SocietyAsset()
                                    {
                                        Name = "Lift " + i, FacilityId = facility.Id, ComplexId = facility.ComplexId, Quantity = 1
                                    });
                                }
                                context.SaveChanges();
                            }
                        }
                        else if (facility.Type == (byte)EnFacilityType.OpenParking)
                        {
                            facility.IsParkingLot = true;

                            int noOf2Parkinglots  = 0;
                            int noOf4Parkinglots  = 0;
                            int noOf24Parkinglots = 0;

                            if (!string.IsNullOrEmpty(facility.Wing))
                            {
                                var arr = facility.Wing.Split(':');
                                if (arr.Length == 3)
                                {
                                    noOf2Parkinglots  = Convert.ToInt32(arr[0]);
                                    noOf4Parkinglots  = Convert.ToInt32(arr[1]);
                                    noOf24Parkinglots = Convert.ToInt32(arr[2]);
                                }

                                facility.Wing = null;
                            }

                            context.Facilities.Add(facility);
                            context.SaveChanges();

                            //Open Parking

                            //For two wheeler
                            if (noOf2Parkinglots > 0)
                            {
                                var flatParking = new FlatParking()
                                {
                                    Facility = new Facility()
                                    {
                                        Id = facility.Id
                                    },
                                    Type = (byte)EnParkingType.TwoWheeler
                                };

                                await flatParkingRepository.Create(flatParking, noOf2Parkinglots);
                            }

                            //For four wheeler
                            if (noOf4Parkinglots > 0)
                            {
                                var flatParking = new FlatParking()
                                {
                                    Facility = new Facility()
                                    {
                                        Id = facility.Id
                                    },
                                    Type = (byte)EnParkingType.FourWheeler
                                };

                                await flatParkingRepository.Create(flatParking, noOf4Parkinglots);
                            }

                            //For two/four wheeler
                            if (noOf24Parkinglots > 0)
                            {
                                var flatParking = new FlatParking()
                                {
                                    Facility = new Facility()
                                    {
                                        Id = facility.Id
                                    },
                                    Type = (byte)EnParkingType.TwoFourWheeler
                                };

                                await flatParkingRepository.Create(flatParking, noOf24Parkinglots);
                            }
                        }
                        else if (facility.Type == (byte)EnFacilityType.Building ||
                                 facility.Type == (byte)EnFacilityType.ClubHouse ||
                                 facility.Type == (byte)EnFacilityType.Gym ||
                                 facility.Type == (byte)EnFacilityType.CommunityHall ||
                                 facility.Type == (byte)EnFacilityType.CommercialSpace ||
                                 facility.Type == (byte)EnFacilityType.School ||
                                 facility.Type == (byte)EnFacilityType.Hospital)
                        {
                            //isWing = true;
                            //isNoOfFloors = true;
                            //isNoOfFlats = true;
                            //isNoOfLifts = true;
                            //isNoOfParkinglots = false;
                            context.Facilities.Add(facility);
                            context.SaveChanges();

                            int flatPerFloor = facility.NoOfFlats / facility.NoOfFloors;

                            for (int j = 0; j < facility.NoOfFloors + 1; j++)
                            {
                                //add Floor
                                var floor = new Floor()
                                {
                                    Name        = (j == 0 ? "Ground Floor" : "Floor " + j.ToString()),
                                    FloorNumber = j,
                                    FacilityId  = facility.Id,
                                    Type        = (byte)EnFloorType.Floor
                                };

                                if (j > 0)
                                {
                                    //add Flats
                                    for (int k = 0; k < flatPerFloor; k++)
                                    {
                                        var flat = new Flat()
                                        {
                                            Name = ((floor.FloorNumber * 100) + (k + 1)).ToString()
                                        };

                                        floor.Flats.Add(flat);
                                    }
                                }

                                context.Floors.Add(floor);
                                context.SaveChanges();
                            }

                            if (facility.NoOfLifts > 0)
                            {
                                for (int i = 1; i <= facility.NoOfLifts; i++)
                                {
                                    context.SocietyAssets.Add(new SocietyAsset()
                                    {
                                        Name = "Lift " + i, FacilityId = facility.Id, ComplexId = facility.ComplexId, Quantity = 1
                                    });
                                }
                                context.SaveChanges();
                            }
                        }
                        else if (facility.Type == (byte)EnFacilityType.Garden ||
                                 facility.Type == (byte)EnFacilityType.SwimmingPool ||
                                 facility.Type == (byte)EnFacilityType.PlayGround ||
                                 facility.Type == (byte)EnFacilityType.PlayArea ||
                                 facility.Type == (byte)EnFacilityType.Temple ||
                                 facility.Type == (byte)EnFacilityType.Mosque ||
                                 facility.Type == (byte)EnFacilityType.Curch ||
                                 facility.Type == (byte)EnFacilityType.Gurudwada)
                        {
                            //do nothing
                            context.Facilities.Add(facility);
                            context.SaveChanges();

                            //scope.isWing = false;
                            //scope.isNoOfFloors = false;
                            //scope.isNoOfFlats = false;
                            //scope.isNoOfLifts = false;
                            //scope.isNoOfParkinglots = false;
                        }

                        //Map facility to society#
                        if (societyId.HasValue)
                        {
                            context.MapsSocietiesToFacilities.Add(new MapSocietiesToFacilities()
                            {
                                SocietyId = societyId.Value, FacilityId = facility.Id
                            });
                        }
                        context.SaveChanges();
                    }

                    return(facilities);
                }
            });

            return(taskResult);
        }
Exemple #6
0
        public Task <FlatParking> Create(FlatParking flatParking, int?count)
        {
            var taskResult = Task.Run(() =>
            {
                using (var context = new DbContext())
                {
                    var cnt = (!count.HasValue || count.Value == 0 || count.Value == 1) ? 1 : count.Value;

                    if (flatParking.Floor != null)
                    {
                        //On floor parking
                        var floor    = context.Floors.First(f => f.Id == flatParking.Floor.Id);
                        var parkings = context.FlatParkings.Count(f => f.FloorId == flatParking.Floor.Id);

                        for (int i = 0; i < cnt; i++)
                        {
                            var newF = new FlatParking();

                            newF.FloorId    = flatParking.Floor.Id;
                            newF.FacilityId = flatParking.Facility.Id;
                            newF.SqftArea   = flatParking.SqftArea;
                            newF.Type       = flatParking.Type;

                            if (cnt != 1)
                            {
                                var no         = (floor.FloorNumber * 100) + parkings + (i + 1);
                                newF.Name      = (no).ToString();
                                newF.ParkingNo = no;
                            }

                            context.FlatParkings.Add(newF);
                            flatParking.Id = newF.Id;
                        }

                        context.SaveChanges();
                        return(flatParking);
                    }
                    else
                    {
                        //Open Parking
                        var parkings = context.FlatParkings.Count(f => f.FloorId == flatParking.Facility.Id);

                        for (int i = 0; i < cnt; i++)
                        {
                            var newF = new FlatParking();

                            newF.FacilityId = flatParking.Facility.Id;
                            newF.SqftArea   = flatParking.SqftArea;
                            newF.Type       = flatParking.Type;

                            if (cnt != 1)
                            {
                                var no         = parkings + (i + 1);
                                newF.Name      = (no).ToString();
                                newF.ParkingNo = no;
                            }

                            context.FlatParkings.Add(newF);
                            flatParking.Id = newF.Id;
                        }

                        context.SaveChanges();
                        return(flatParking);
                    }
                }
            });

            return(taskResult);
        }