Ejemplo n.º 1
0
        public void Update(int id, BasicPlaceBindingModel item)
        {
            //todo validate against is user owner of the travel

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                Place property = Mapper.Map<Place>(item);

                var entry = db.Entry(property);
                entry.State = EntityState.Modified;

                entry.Property(e => e.TravelId).IsModified = false;
                entry.Property(e => e.ParentId).IsModified = false;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    //todo check if exists
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public BasicPlaceBindingModel Add(BasicPlaceBindingModel item)
        {
            //todo validate against is user owner of the travel

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                Place place = Mapper.Map<Place>(item);

                db.Places.Add(place);
                db.SaveChanges();

                return Mapper.Map<BasicPlaceBindingModel>(place);
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutPlace(int id, BasicPlaceBindingModel place)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                pr.Update(id, place);
                return StatusCode(HttpStatusCode.NoContent);
            }
            catch
            {
                return BadRequest();
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult PostPlace(BasicPlaceBindingModel place)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var item = pr.Add(place);
                return StatusCode(HttpStatusCode.Created);
            }
            catch
            {
                return BadRequest();
            }
        }