コード例 #1
0
        public IActionResult Post(ProductModel productModel)
        {
            try {
                Product product = _mapper.Map <Product>(productModel);
                assignmentQueries.Add(product);

                return(Ok(_mapper.Map <ProductModel>(product)));
            }
            catch (Exception) {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Server Error"));
            }
        }
コード例 #2
0
        public IActionResult Post(StaffModel staffModel)
        {
            try {
                var staff = _mapper.Map <Staff>(staffModel);
                //  var location = _linkGenerator.GetPathByAction("staff-members/{id}", "Staff", new { id = staff.Staff_Id });

                //if (string.IsNullOrWhiteSpace(location)) {

                //    return BadRequest("Could not show current staff");
                //}

                assignmentQueries.Add(staff);
                if (assignmentQueries.saveChangestoDatabase())
                {
                    return(Ok(staffModel));
                    //return Created($"/api/Staff/staff-members/{staff.Staff_Id}", _mapper.Map<StaffModel>(staff));
                }
                else
                {
                    return(BadRequest("Data Can not be added"));
                }
            } catch (Exception) {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Sever not responding"));
            };
        }