예제 #1
0
        private Location GetLocation(AddJobOfferViewModel model)
        {
            var location = new Location()
            {
                Longitude = model.Longitude,
                Latitude = model.Latitude,
                Country = model.Country,
                City = model.City,
                PostCode = model.PostCode
            };

            this.data.Locations.Add(location);
            this.data.SaveChanges();

            return location;
        }
예제 #2
0
        public IHttpActionResult Add(AddJobOfferViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var jobOffer = AutoMapper.Mapper.Map<JobOffer>(model);

                var location = this.GetLocation(model);
                jobOffer.Location = location;
                jobOffer.LocationId = location.Id;

                this.data.JobOffers.Add(jobOffer);
                this.data.SaveChanges();

                model.Id = jobOffer.Id;

                this.data.SaveChanges();

                return this.Ok(model);
            }

            return this.BadRequest();
        }