Пример #1
0
        public bool AddZone(ManageZoneAdd manageZone, TaxiAppzDBContext context, LoggedInUser loggedInUser)
        {
            var serviceExist = context.TabServicelocation.FirstOrDefault(t => t.IsDeleted == 0 && t.Servicelocid == manageZone.Serviceslocid);

            if (serviceExist == null)
            {
                throw new DataValidationException($"Service location does not already exists.");
            }

            TabZone tabZone = new TabZone();

            tabZone.Zonename     = manageZone.ZoneName;
            tabZone.Servicelocid = manageZone.Serviceslocid;
            tabZone.Unit         = manageZone.Unit;
            tabZone.IsActive     = 1;
            tabZone.IsDeleted    = 0;
            tabZone.CreatedBy    = tabZone.UpdatedBy = loggedInUser.UserName;
            tabZone.CreatedAt    = tabZone.UpdatedAt = Extention.GetDateTime();
            context.TabZone.Add(tabZone);
            context.SaveChanges();

            foreach (var zonepolygon in manageZone.ZonePolygoneList)
            {
                TabZonepolygon tabZonepolygon = new TabZonepolygon();
                tabZonepolygon.Longitudes = zonepolygon.Lng;
                tabZonepolygon.Latitudes  = zonepolygon.Lat;
                tabZonepolygon.IsActive   = 1;
                tabZonepolygon.CreatedBy  = tabZonepolygon.UpdatedBy = loggedInUser.UserName;
                tabZonepolygon.CreatedAt  = tabZonepolygon.UpdatedAt = Extention.GetDateTime();
                tabZonepolygon.Zoneid     = tabZone.Zoneid;
                context.TabZonepolygon.Add(tabZonepolygon);
            }
            context.SaveChanges();
            return(true);
        }
Пример #2
0
        public bool EditZone(ManageZoneAdd manageZone, TaxiAppzDBContext context, LoggedInUser loggedInUser)
        {
            var serviceExist = context.TabServicelocation.FirstOrDefault(t => t.IsDeleted == 0 && t.Servicelocid == manageZone.Serviceslocid);

            if (serviceExist == null)
            {
                throw new DataValidationException($"Service location does not already exists.");
            }

            var setzone          = context.TabZone.Where(z => z.Zoneid == manageZone.Zoneid && z.IsDeleted == 0).FirstOrDefault();
            var deletezonepolyon = context.TabZonepolygon.Where(z => z.Zoneid == manageZone.Zoneid).ToList();

            if (setzone != null)
            {
                setzone.Zonename     = manageZone.ZoneName;
                setzone.Servicelocid = manageZone.Serviceslocid;
                setzone.Unit         = manageZone.ZoneName;
                context.TabZone.Update(setzone);
                context.TabZonepolygon.RemoveRange(deletezonepolyon);
                context.SaveChanges();
                foreach (var zonepoly in manageZone.ZonePolygoneList)
                {
                    TabZonepolygon tabZonepolygon = new TabZonepolygon();
                    tabZonepolygon.Latitudes  = zonepoly.Lat;
                    tabZonepolygon.Longitudes = zonepoly.Lng;
                    tabZonepolygon.Zoneid     = setzone.Zoneid;
                    tabZonepolygon.UpdatedBy  = tabZonepolygon.CreatedBy = loggedInUser.UserName;
                    tabZonepolygon.UpdatedAt  = tabZonepolygon.CreatedAt = DateTime.UtcNow;
                    context.TabZonepolygon.Add(tabZonepolygon);
                }
                context.SaveChanges();
                return(true);
            }
            return(false);
        }