Exemple #1
0
        public IHttpActionResult Post([FromBody] EmployeeAdd newItem)
        {
            if (Request.GetRouteData().Values["id"] != null)
            {
                return(BadRequest("Invalid request URI"));
            }

            if (newItem == null)
            {
                return(BadRequest("Must send an entity body with the request"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var addedItem = m.EmployeeAdd(newItem);

            if (addedItem == null)
            {
                return(BadRequest("Cannot add the object"));
            }

            // HTTP 201
            var uri = Url.Link("DefaultApi", new { id = addedItem.Id });

            return(Created(uri, addedItem));
        }
Exemple #2
0
        public EmployeeBase EmployeeAdd(EmployeeAdd newItem)
        {
            if (newItem == null)
            {
                return(null);
            }
            var addedItem = ds.Employees.Add(Mapper.Map <Employee>(newItem));

            ds.SaveChanges();

            return((addedItem == null) ? null : Mapper.Map <EmployeeBase>(addedItem));
        }