Ejemplo n.º 1
0
        public async Task <IHttpActionResult> DeletePopularPlace(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                popularPlace city = await db.popularPlaces.FindAsync(id);

                if (city == null)
                {
                    return(NotFound());
                }
                var data = city.CompanyOffices.ToList();
                foreach (var office in data)
                {
                    office.popularPlaceId = null;
                }
                db.popularPlaces.Remove(city);
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    string s = e.ToString();
                }

                return(Ok(city));
            }
            return(BadRequest("Not login"));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> UpdatePopularPlace(popularPlace city)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                city.status          = "a";
                city.updatedBy       = User.Identity.GetUserId();
                city.updatedOn       = DateTime.UtcNow;
                db.Entry(city).State = EntityState.Modified;

                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(StatusCode(HttpStatusCode.NoContent));
            }
            return(BadRequest("Not login"));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> OfficeBranch(CompanyOffice branch, string city, string popularPlace, string exectLocation, string SaveOrUpdate)
        {
            //var company = await db.Companies.FindAsync(companyId);
            if (city != null)
            {
                var citydb = db.Cities.FirstOrDefault(x => x.cityName.Equals(city, StringComparison.OrdinalIgnoreCase));
                if (citydb == null)
                {
                    City cit = new City();
                    cit.cityName = city;
                    cit.addedBy  = User.Identity.GetUserId();
                    cit.addedBy  = User.Identity.GetUserId();
                    cit.addedOn  = DateTime.UtcNow;
                    db.Cities.Add(cit);
                    await db.SaveChangesAsync();

                    // loc.cityId = cit.Id;
                    branch.cityId = cit.Id;
                    if (popularPlace != null)
                    {
                        popularPlace pop = new popularPlace();
                        pop.cityId  = cit.Id;
                        pop.name    = popularPlace;
                        pop.addedBy = User.Identity.GetUserId();
                        pop.addedOn = DateTime.UtcNow;
                        db.popularPlaces.Add(pop);
                        await db.SaveChangesAsync();

                        //  loc.popularPlaceId = pop.Id;
                        branch.popularPlaceId = pop.Id;
                    }
                }
                else
                {
                    // loc.cityId = citydb.Id;
                    branch.cityId = citydb.Id;
                    if (popularPlace != null)
                    {
                        var ppp = db.popularPlaces.FirstOrDefault(x => x.City.cityName.Equals(city, StringComparison.OrdinalIgnoreCase) && x.name.Equals(popularPlace, StringComparison.OrdinalIgnoreCase));
                        if (ppp == null)
                        {
                            popularPlace pop = new popularPlace();
                            pop.cityId  = citydb.Id;
                            pop.name    = popularPlace;
                            pop.addedBy = User.Identity.GetUserId();
                            pop.addedOn = DateTime.UtcNow;
                            db.popularPlaces.Add(pop);
                            await db.SaveChangesAsync();

                            //   loc.popularPlaceId = pop.Id;
                            branch.popularPlaceId = pop.Id;
                        }
                        else
                        {
                            //   loc.popularPlaceId = ppp.Id;
                            branch.popularPlaceId = ppp.Id;
                        }
                    }
                }
                branch.exectLocation = exectLocation;
                if (SaveOrUpdate == "Save")
                {
                    db.CompanyOffices.Add(branch);
                }
                else if (SaveOrUpdate == "Update")
                {
                    //var bra = db.CompanyOffices.Find(branch.Id);
                    //bra.popularPlaceId = branch.popularPlaceId;
                    //bra.since = branch.since;
                    //bra.cityId = branch.cityId;
                    //bra.contactNo1 = branch.contactNo1;
                    //bra.contactNo2 = branch.contactNo2;
                    //await db.SaveChangesAsync();
                    db.Entry(branch).State = EntityState.Modified;
                }
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    string s = e.ToString();
                }
            }
            var ret = await(from br in db.CompanyOffices
                            where br.Id.Equals(branch.Id)
                            select new
            {
                id             = br.Id,
                cityId         = br.cityId,
                cityName       = br.City.cityName,
                popularPlace   = br.popularPlace.name,
                popularPlaceId = br.popularPlaceId,
                contactNo1     = br.contactNo1,
                contactNo2     = br.contactNo2,
                since          = br.since,
                exectLocation  = br.exectLocation,
            }).FirstOrDefaultAsync();

            return(Ok(ret));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> HeadOfficeLocation(Company branch, string city, string popularPlace, string exectLocation)
        {
            // var branch = await db.Companies.FindAsync(companyId);
            if (city != null)
            {
                var citydb = db.Cities.FirstOrDefault(x => x.cityName.Equals(city, StringComparison.OrdinalIgnoreCase));
                if (citydb == null)
                {
                    City cit = new City();
                    cit.cityName = city;
                    cit.addedBy  = User.Identity.GetUserId();
                    cit.addedBy  = User.Identity.GetUserId();
                    cit.addedOn  = DateTime.UtcNow;
                    db.Cities.Add(cit);
                    await db.SaveChangesAsync();

                    // loc.cityId = cit.Id;
                    branch.cityId = cit.Id;
                    if (popularPlace != null)
                    {
                        popularPlace pop = new popularPlace();
                        pop.cityId  = cit.Id;
                        pop.name    = popularPlace;
                        pop.addedBy = User.Identity.GetUserId();
                        pop.addedOn = DateTime.UtcNow;
                        db.popularPlaces.Add(pop);
                        await db.SaveChangesAsync();

                        //  loc.popularPlaceId = pop.Id;
                        branch.popularPlaceId = pop.Id;
                    }
                }
                else
                {
                    // loc.cityId = citydb.Id;
                    branch.cityId = citydb.Id;
                    if (popularPlace != null)
                    {
                        var ppp = db.popularPlaces.FirstOrDefault(x => x.City.cityName.Equals(city, StringComparison.OrdinalIgnoreCase) && x.name.Equals(popularPlace, StringComparison.OrdinalIgnoreCase));
                        if (ppp == null)
                        {
                            popularPlace pop = new popularPlace();
                            pop.cityId  = citydb.Id;
                            pop.name    = popularPlace;
                            pop.addedBy = User.Identity.GetUserId();
                            pop.addedOn = DateTime.UtcNow;
                            db.popularPlaces.Add(pop);
                            await db.SaveChangesAsync();

                            //   loc.popularPlaceId = pop.Id;
                            branch.popularPlaceId = pop.Id;
                        }
                        else
                        {
                            //   loc.popularPlaceId = ppp.Id;
                            branch.popularPlaceId = ppp.Id;
                        }
                    }
                }
                branch.exectLocation = exectLocation;

                try
                {
                    db.Entry(branch).State = EntityState.Modified;
                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    string s = e.ToString();
                }
            }
            //var ret = await (from br in db.CompanyOffices
            //                 where br.Id.Equals(branch.Id)
            //                 select new
            //                 {
            //                     id = br.Id,
            //                     cityId = br.cityId,
            //                     cityName = br.City.cityName,
            //                     popularPlace = br.popularPlace.name,
            //                     popularPlaceId = br.popularPlaceId,
            //                     contactNo1 = br.contactNo1,
            //                     contactNo2 = br.contactNo2,
            //                     since = br.since,
            //                     exectLocation = br.exectLocation,
            //                 }).FirstOrDefaultAsync();
            return(Ok("Done"));
        }
Ejemplo n.º 5
0
        public async Task <bool> SaveLocation(string city, string popularPlace)
        {
            if (city != null && city != "undefined")
            {
                var citydb = db.Cities.FirstOrDefault(x => x.cityName.Equals(city, StringComparison.OrdinalIgnoreCase));
                if (citydb == null)
                {
                    City cit = new City();
                    cit.cityName = city;
                    cit.addedBy  = System.Web.HttpContext.Current.User.Identity.GetUserId();
                    cit.addedBy  = System.Web.HttpContext.Current.User.Identity.GetUserId();
                    cit.addedOn  = DateTime.UtcNow;
                    cit.status   = "a";
                    db.Cities.Add(cit);
                    await db.SaveChangesAsync();

                    if (popularPlace != null && popularPlace != "undefined")
                    {
                        popularPlace pop = new popularPlace();
                        pop.status = "p";
                        try
                        {
                            ElectronicsController.Coordinates co = ElectronicsController.GetLongitudeAndLatitude(popularPlace, city);
                            if (co.status)
                            {
                                pop.longitude = co.longitude;
                                pop.latitude  = co.latitude;
                                pop.status    = "a";
                            }
                        }
                        catch (Exception e)
                        {
                        }

                        pop.cityId  = cit.Id;
                        pop.name    = popularPlace;
                        pop.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                        pop.addedOn = DateTime.UtcNow;

                        db.popularPlaces.Add(pop);
                        await db.SaveChangesAsync();
                    }
                }
                else
                {
                    if (popularPlace != null && popularPlace != "undefined")
                    {
                        var ppp = db.popularPlaces.FirstOrDefault(x => x.City.cityName.Equals(city, StringComparison.OrdinalIgnoreCase) && x.name.Equals(popularPlace, StringComparison.OrdinalIgnoreCase));
                        if (ppp == null)
                        {
                            popularPlace pop = new popularPlace();
                            pop.status = "p";
                            try
                            {
                                ElectronicsController.Coordinates co = ElectronicsController.GetLongitudeAndLatitude(popularPlace, city);
                                if (co.status)
                                {
                                    pop.longitude = co.longitude;
                                    pop.latitude  = co.latitude;
                                    pop.status    = "a";
                                }
                            }
                            catch (Exception e)
                            {
                            }
                            pop.cityId  = citydb.Id;
                            pop.name    = popularPlace;
                            pop.addedBy = System.Web.HttpContext.Current.User.Identity.GetUserId();
                            pop.addedOn = DateTime.UtcNow;

                            db.popularPlaces.Add(pop);
                            await db.SaveChangesAsync();
                        }
                    }
                }
            }
            return(true);
        }