コード例 #1
0
        public void Update(Consultant consultant)
        {
            var oldConsulant = _consultants.Single(c => c.ID == consultant.ID);
            _consultants.Remove(oldConsulant);

            _consultants.Add(consultant);
        }
コード例 #2
0
        public int Add(Consultant consultant)
        {
            int newId = _consultants.Max(c => c.ID) + 1;
            consultant.ID = newId;

            _consultants.Add(consultant);
            return newId;
        }
コード例 #3
0
        public void Put([FromUri] int id, Consultant consultant)
        {
            // check if consultant exists
            var oldConsultant = _repository.GetAll().FirstOrDefault(c => c.ID == id);

            if (oldConsultant == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            consultant.ID = id;
            consultant.Owner = Thread.CurrentPrincipal.Identity.Name;
            _repository.Update(consultant);
        }
コード例 #4
0
        public HttpResponseMessage Post(Consultant consultant)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            consultant.Owner = Thread.CurrentPrincipal.Identity.Name;
            var id = _repository.Add(consultant);

            var response = new HttpResponseMessage(HttpStatusCode.Created);
            response.Headers.Location = new Uri(Request.RequestUri.AbsoluteUri + "/" + id.ToString());
            
            return response;
        }