Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public bool DeleteZone(long zoneid, TaxiAppzDBContext context, LoggedInUser loggedInUser)
        {
            TabZone tabZone = new TabZone();
            var     tabzone = context.TabZone.Include(t => t.TabZonepolygon).Where(z => z.Zoneid == zoneid).FirstOrDefault();

            if (tabzone != null)
            {
                tabzone.IsDeleted = 1;
                tabzone.DeletedAt = DateTime.UtcNow;
                tabzone.DeletedBy = loggedInUser.UserName;
                context.TabZone.Update(tabzone);
                foreach (var tabpoly in tabzone.TabZonepolygon.ToList())
                {
                    tabpoly.IsDeleted = 1;
                    tabpoly.DeletedAt = DateTime.UtcNow;
                    tabpoly.DeletedBy = loggedInUser.UserName;
                    context.TabZonepolygon.Update(tabpoly);
                }
                context.SaveChanges();
                return(true);
            }
            return(false);
        }