Ejemplo n.º 1
0
        public CreatorTravelBindingModel Update(int id, SimpleCreatorTravelBindingModel item)
        {
            //todo validate user role
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                Travel oldTravel = db.Travels.Where(x => x.Id == id).FirstOrDefault();

                Travel travel = Mapper.Map<SimpleCreatorTravelBindingModel, Travel>(item, oldTravel);

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

                entry.Property(e => e.ApproverId).IsModified = false;
                entry.Property(e => e.CreatorId).IsModified = false;
                entry.Property(e => e.ApprovalStatus).IsModified = false;


                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    //todo check if exists
                    throw;
                }

                return Mapper.Map<CreatorTravelBindingModel>(travel);
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutTravel(int id, SimpleCreatorTravelBindingModel travel)
        {
            if (!ModelState.IsValid)
            {
                Logger.Instance.LogException(new Exception("Invalid Model State"), LogLevel.error);
                return BadRequest(ModelState);
            }
            if (id != travel.Id)
            {
                Logger.Instance.LogException(new Exception("id != travel.Id" + id + " " + travel.Id), LogLevel.error);
                return BadRequest();
            }

            try
            {
                tr.Update(id, travel);
                return StatusCode(HttpStatusCode.NoContent);
            }
            catch (Exception e)
            {
                Logger.Instance.LogException(e, LogLevel.error);
                return BadRequest();
            }
        }