示例#1
0
        public async Task <IActionResult> DeleteAssignment([FromRoute] Guid id)
        {
            try
            {
                var result = await _assignmentService.Delete(id);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex.Message);
                return(StatusCode(500, ex.Message));
            }
        }
        public IActionResult Delete(int id)
        {
            if (id < 1)
            {
                return(RedirectToAction(nameof(List)));
            }

            var assignment = _assignmentService.GetById(id);

            if (assignment == null)
            {
                return(RedirectToAction(nameof(List)));
            }

            _assignmentService.Delete(assignment);

            return(Json(null));
        }
示例#3
0
        public JsonResult Delete(int id)
        {
            var isAdmin    = User.IsInRole("admin");
            var assignment = _assignmentService.FindBy(item => item.Id == id && (isAdmin || item.CustomerId == CustomerId)).FirstOrDefault();

            if (assignment != null)
            {
                if (assignment.StatusId > 2 && !isAdmin)
                {
                    return(Json(new { Error = "Cannot delete submitted or funded assignments" }));
                }
                if (assignment.StatusId >= 4 && isAdmin)
                {
                    return(Json(new { Error = "Cannot delete closed or funded assignments" }));
                }
                _assignmentService.Delete(id);
                _uow.SaveChanges();
                return(Json(new { Done = 1 }));
            }
            return(Json(new { Error = "Assignment not exist." }));
        }