Ejemplo n.º 1
0
        internal Event CreateEvent(ApiEvent apiEvent, ApiLocation apiLocation, Location location)
        {
            try
            {
                //Create a new event
                var addedEvent = new Event
                {
                    EventId    = apiEvent.Id,
                    DateTime   = apiEvent.DateTime,
                    Name       = apiEvent.Name,
                    Summary    = apiEvent.Summary,
                    Url        = apiEvent.Url,
                    Type       = apiEvent.Type,
                    Coordinate = apiLocation.Gps,

                    Location = location
                };

                //Add the event to the location
                location.Events.Add(addedEvent);

                return(addedEvent);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 2
0
        internal async Task <Location> GetOrCreateLocation(ApiLocation apiLocation)
        {
            try
            {
                //Search for location by name
                Location location = await GetLocationByName(apiLocation.Name);

                //If location doesn't exist in db create it
                //If location exists keep using that instance
                if (location == null)
                {
                    location = new Location
                    {
                        Name = apiLocation.Name
                    };

                    await context.Locations.AddAsync(location);

                    await context.SaveChangesAsync();
                }

                return(location);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Put(int id, [FromBody] ApiLocation newLocation)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var entity = db.Locations.FirstOrDefault(x => x.LocationId == id);

                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                           "Location with Id " + id.ToString() + " not found to update."));
                    }

                    PropertyCopier <ApiLocation, Location> .Copy(newLocation, entity);

                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  "Location with Id " + id.ToString() + " found and updated."));
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                       "Error in the code"));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Get()
        {
            try
            {
                List <Location> entities = db.Locations.Where(x => x.LocationIsActive == true).ToList();

                if (entities == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                       "No Locations Found."));
                }

                List <ApiLocation> apiLocations = new List <ApiLocation>();

                foreach (var record in entities)
                {
                    ApiLocation apiLocation = new ApiLocation();
                    PropertyCopier <Location, ApiLocation> .Copy(record, apiLocation);

                    apiLocations.Add(apiLocation);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, apiLocations));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                   "Error in the code"));
            }
        }
Ejemplo n.º 5
0
        public static ApiLocation GetLocation(int id)
        {
            var location = db.Locations.Find(id);

            var locationApi = new ApiLocation();

            PropertyCopier <Location, ApiLocation> .Copy(location, locationApi, true);

            return(locationApi);
        }
Ejemplo n.º 6
0
        public bool Update(ApiLocation apiLocation)
        {
            Location location = new Location
            {
                ID         = apiLocation.ID,
                Name       = apiLocation.Name,
                CustomerID = apiLocation.CustomerID
            };

            return(locationManager.UpdateLocation(location));
        }
 public ActionResult Edit(ApiLocation location)
 {
     if (client.UpdateLocation(location))
     {
         ViewBag.message = "Location Changed";
     }
     else
     {
         ViewBag.message = "Location not Changed, error";
     }
     return(RedirectToAction("Details", new { id = location.LocationId }));
 }
        public bool Update(ApiLocation apiLocation)
        {
            //string id = User.Identity.Name;
            Location location = new Location
            {
                ID         = apiLocation.ID,
                Name       = apiLocation.Name,
                CustomerID = Helper.getCustID()
            };

            return(locationManager.UpdateLocation(location));
        }
        public ApiLocation Get(int ID)
        {
            Location location = locationManager.FindLocationbyID(ID);

            ApiLocation apiLocation = new ApiLocation
            {
                ID   = location.ID,
                Name = location.Name
            };

            return(apiLocation);
        }
Ejemplo n.º 10
0
        public static void PostLocation(ApiLocation lo)
        {
            // Create a new EF Customer.
            Location l = new Location();

            // Copy the Simplified customer to the EF customer using the tool I provided.
            PropertyCopier <ApiLocation, Location> .Copy(lo, l, true);

            // Tell EF we want to add the customer.
            db.Locations.Add(l);

            //Save changes
            db.SaveChanges();
        }
Ejemplo n.º 11
0
        public static void PutLocation(int id, ApiLocation al)
        {
            // Create a new car
            Location l = db.Locations.Find(id);

            // Copy car
            if (al.LocationId == id)
            {
                PropertyCopier <ApiLocation, Location> .Copy(al, l, true);

                db.Entry(l).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
        public ActionResult Create(FormCollection form)
        {
            ApiLocation location = new ApiLocation();

            location.LocationAddress   = form["LocationAddress"];
            location.LocationStateProv = form["LocationStateProv"];
            if (client.CreateLocation(location))
            {
                return(RedirectToAction("Locations"));
            }
            else
            {
                return(View(location));
            }
        }
Ejemplo n.º 13
0
        public HttpResponseMessage PostLocation([FromBody] ApiLocation lo)
        {
            try
            {
                DBAccess.PostLocation(lo);
            }
            catch (Exception e)
            {
                // ERROR
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot create record."));
            }

            // All OK
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 14
0
        public HttpResponseMessage PutLocation(int id, [FromBody] ApiLocation al)
        {
            try
            {
                // Persist our change.
                DBAccess.PutLocation(id, al);
            }
            catch (Exception e)
            {
                // ERROR
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot update record: " + e));
            }

            // All OK
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public bool CreateLocation(ApiLocation location)
        {
            client.BaseAddress = new Uri("http://localhost:81/");

            var postTask = client.PostAsJsonAsync("api/Location", location);

            postTask.Wait();
            var result = postTask.Result;

            if (result.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool UpdateLocation(ApiLocation location)
        {
            client.BaseAddress = new Uri("http://localhost:81/");

            var putTask = client.PutAsJsonAsync <ApiLocation>("api/Location/" + location.LocationId, location);

            putTask.Wait();
            var result = putTask.Result;

            if (result.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public List <ApiLocation> GetList()
        {
            List <Location> locationsList = locationManager.getAllLocation();

            List <ApiLocation> apiLocationList = new List <ApiLocation>();

            foreach (Location location in locationsList)
            {
                ApiLocation apiLocation = new ApiLocation
                {
                    ID   = location.ID,
                    Name = location.Name
                };

                apiLocationList.Add(apiLocation);
            }

            return(apiLocationList);
        }
Ejemplo n.º 18
0
        public static ApiLocation ToApiEntity(this DbLocation entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var mappedEntity = new ApiLocation();

            mappedEntity.AddressNumber     = entity.AddressNumber;
            mappedEntity.AddressPostalCode = entity.AddressPostalCode;
            mappedEntity.AddressCity       = entity.AddressCity;
            mappedEntity.AddressProvince   = entity.AddressProvince;
            mappedEntity.AddressStreet     = entity.AddressStreet;
            mappedEntity.Description       = entity.Description;
            mappedEntity.Name        = entity.Name;
            mappedEntity.PricePerDay = entity.PricePerDay;
            mappedEntity.Capacity    = entity.Capacity;
            return(mappedEntity);
        }
Ejemplo n.º 19
0
        public IEnumerable <ApiLocation> Get(string name = null, string cityOrPostcode = null, string province = null, DateTime?from = null, DateTime?to = null, int?minCapacity = null)
        {
            var locationsRepository = _unitOfWork.LocationsRepository;

            LocationFilter filter = new LocationFilter();

            filter.Name           = name;
            filter.CityOrPostcode = cityOrPostcode;
            filter.Province       = province;
            filter.From           = from;
            filter.To             = to;
            filter.MinCapacity    = minCapacity;
            IList <DbLocation> locations = locationsRepository.GetAllWithFilter(filter);

            return(locations.Select(x =>
            {
                ApiLocation location = x.ToApiEntity();
                location.DetailsPageUrl = Uri.EscapeUriString(string.Format(DetailsPageUrlTemplate, x.Id));
                location.BookingPageUrl = Uri.EscapeUriString(string.Format(BookingPageUrlTemplate, x.Id));
                location.BannerImageUrl = Uri.EscapeUriString(string.Format(BannerImageBaseUrl, x.Id, x.BannerImageFileName));
                return location;
            }));
        }
Ejemplo n.º 20
0
        public HttpResponseMessage Post([FromBody] ApiLocation newLocation)
        {
            if (ModelState.IsValid)
            {
                Location c = new Location();
                PropertyCopier <ApiLocation, Location> .Copy(newLocation, c);

                db.Locations.Add(c);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                       "Cannot add new Location, Try again." + e.StackTrace + "---" + e.InnerException));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, "Location added."));
        }
Ejemplo n.º 21
0
        public HttpResponseMessage Get(int id)
        {
            try
            {
                var entity = db.Locations.Find(id);

                if (entity == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                       "Location with Id " + id.ToString() + " not found."));
                }

                var myApiLocation = new ApiLocation();

                PropertyCopier <Location, ApiLocation> .Copy(entity, myApiLocation);

                return(Request.CreateResponse(HttpStatusCode.OK, myApiLocation));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                   "Error in the code"));
            }
        }
Ejemplo n.º 22
0
 public ClientOptions()
 {
     Location = ApiLocation.USEast;
     Timeout  = 3000;
 }
        public ActionResult Delete(int id)
        {
            ApiLocation location = client.GetLocation(id);

            return(View(location));
        }
 internal static LocationMapping FromApi(ApiLocation location)
 => LocationMapping.Create(location.Latitude, location.Longitude);