コード例 #1
0
        public JsonResult Delete(int id)
        {
            var result = new TaskResult();

            try
            {
                var job = _jobsService.GetById(id);

                if (job == null)
                {
                    result.AddErrorMessage("No puedes eliminar un puesto que no existe.");
                }
                else if (job.UserId == _currentUser.UserId)
                {
                    if (!job.IsActive)
                    {
                        result.AddErrorMessage("El puesto que intentas eliminar ya está eliminado.");
                    }
                    else
                    {
                        result = _jobsService.Delete(job);
                    }
                }
                else
                {
                    result.AddErrorMessage("No puedes eliminar un puesto que no creaste.");
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                result.AddErrorMessage(ex.Message);
            }
            return(Json(result));
        }
コード例 #2
0
        public async Task <IActionResult> Delete([FromQuery][Required] int jobId)
        {
            if (await _jobsService.Delete(jobId) == EntityState.Deleted)
            {
                return(Ok());
            }

            return(NoContent());
        }
コード例 #3
0
 public HttpResponseMessage Delete(int id)
 {
     if (!ModelState.IsValid)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
     jobsService.Delete(id);
     return(Request.CreateResponse(HttpStatusCode.OK, "Deleted"));
 }
コード例 #4
0
        public async Task <ActionResult> Delete(long id)
        {
            var deleted = await _service.Delete(id, _currentUserService.GetId());

            if (!deleted)
            {
                return(BadRequest());
            }

            return(Ok());
        }