예제 #1
0
        public HttpResponseMessage Put(int degreeId, DegreeApiModel model)
        {
            if (degreeId == 0 || model == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            model.Id = degreeId;
            var command = new UpdateDegree(User, degreeId);
            Mapper.Map(model, command);
            _updateHandler.Handle(command);

            return Request.CreateResponse(HttpStatusCode.OK, "Degree was successfully saved.");
        }
예제 #2
0
        public HttpResponseMessage Post(DegreeApiModel newModel)
        {
            if ( (newModel == null) ||
                 (newModel.Title == null) )
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError);
            }

            var createDeepDegreeCommand = new CreateDegree(User, newModel.Title)
            {
                YearAwarded = newModel.YearAwarded,
                InstitutionId = newModel.InstitutionId
            };
            _createDegree.Handle(createDeepDegreeCommand);

            var id = createDeepDegreeCommand.CreatedDegree.RevisionId;
            return Request.CreateResponse(HttpStatusCode.OK, id);
        }
예제 #3
0
        public HttpResponseMessage Post(DegreeApiModel model)
        {
            if (model == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            var command = new CreateDegree(User);
            Mapper.Map(model, command);
            _createHandler.Handle(command);

            var response = Request.CreateResponse(HttpStatusCode.Created, "Degree was successfully created.");
            var url = Url.Link(null, new
            {
                controller = "MyDegrees",
                action = "Get",
                degreeId = command.CreatedDegreeId,
            });
            Debug.Assert(url != null);
            response.Headers.Location = new Uri(url);
            return response;
        }
예제 #4
0
        public HttpResponseMessage Put(int degreeId, DegreeApiModel model)
        {
            if ((degreeId == 0) || (model == null))
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError);
            }

            try
            {
                var updateDegreeCommand = Mapper.Map<UpdateDegree>(model);
                updateDegreeCommand.UpdatedOn = DateTime.UtcNow;
                updateDegreeCommand.Principal = User;
                _updateDegree.Handle(updateDegreeCommand);
            }
            catch (Exception ex)
            {
                var responseMessage = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.NotModified,
                    Content = new StringContent(ex.Message),
                    ReasonPhrase = "Degree update error"
                };
                throw new HttpResponseException(responseMessage);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }