예제 #1
0
            public async Task<HttpResponseMessage> Update(int id, DepartmentModel model)
             {
                try
                {
                    int result = await service.UpdateAsync(Mapper.Map<IDepartment>(model));

                    if (result >= 1)
                    {
                        return Request.CreateResponse(HttpStatusCode.OK, model);
                    }
                    else
                    {
                        return Request.CreateResponse(HttpStatusCode.BadRequest, "Error while trying to edit task.");
                    }
                }
                catch (Exception ex)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                }
            }
예제 #2
0
            public async Task<HttpResponseMessage> Insert(DepartmentModel dep)
            {
                try
                {
                    int result = await service.AddAsync(Mapper.Map<IDepartment>(dep));

                    if (result == 0)
                    {
                        return Request.CreateResponse(HttpStatusCode.BadRequest, "Add operation error.");
                    }

                    else
                    {
                        return Request.CreateResponse(HttpStatusCode.OK, result);
                    }
                }
                catch (Exception ex)
                {

                    return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                }
            }