예제 #1
0
        public HttpResponseMessage Create(PerformerTimeFreeView view)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var original = view.convert(this._context);
                    original.changed = DateTime.UtcNow;
                    this._context.performerTimesFree.Add(original);
                    this._context.SaveChanges();
                    view = new PerformerTimeFreeView(original);

                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, view);
                    //response.Headers.Location = new Uri(Url.Link("Default", new { id = performer.performerID }));
                    return(response);
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
예제 #2
0
        public HttpResponseMessage Update(PerformerTimeFreeView view)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var original = this._context.performerTimesFree.FirstOrDefault(a => a.id == view.id);
                    original.changed = DateTime.UtcNow;
                    AutoMapper.Mapper.CreateMap <PerformerTimeFree, PerformerTimeFree>();
                    AutoMapper.Mapper.Map <PerformerTimeFree, PerformerTimeFree>(view.convert(this._context), original);
                    this._context.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }