Beispiel #1
0
        public async Task <IActionResult> Delete(string id)
        {
            if (!CurrentUser.Routes.Any(s => s.Id == id))
            {
                if (!User.IsInRole("Administrator"))
                {
                    logger.LogInformation(
                        string.Format(SetLog.NotTheAuthor,
                                      CurrentUser.UserName,
                                      CurrentController,
                                      id
                                      ));

                    AddDangerNotification(string.Format(Notifications.DeleteFail));

                    return(Redirect($"/Routes/Details/{id}"));
                }
            }
            try
            {
                var result = await routeService.DeleteAsync(id);

                if (!result)
                {
                    AddDangerNotification(Notifications.Fail);
                    return(Redirect("/Routes"));
                }

                logger.LogInformation(
                    string.Format(SetLog.Delete,
                                  CurrentUser.UserName,
                                  CurrentController,
                                  id
                                  ));

                AddSuccessNotification(Notifications.Delete);

                return(Redirect($"/Routes"));
            }
            catch (System.Exception e)
            {
                logger.LogError(string.Format(SetLog.Error,
                                              CurrentUser.UserName,
                                              CurrentController,
                                              e.Message));

                AddDangerNotification(Notifications.Fail);

                return(Redirect($"/Routes"));
            }
        }
        public async Task <ResponseDto> Delete(int id)
        {
            int result = await _routeService.DeleteAsync(id);

            if (result == 0)
            {
                return(new ResponseDto(ResponseCode.LogicError, "Xóa không thành công"));
            }
            if (result == -1)
            {
                return(new ResponseDto(ResponseCode.LogicError, "Không tìm thấy đối tượng cần xóa"));
            }
            return(new ResponseDto(ResponseCode.Success, "Xóa thành công"));
        }
Beispiel #3
0
        public async Task <ActionResult> DeleteRoute(Guid routeId)
        {
            if (routeId == null || routeId == Guid.Empty)
            {
                return(StatusCode(400, $"{nameof(routeId)} can't be empty."));
            }

            var route = await _routeService.GetByIdAsync(routeId);

            if (route != null)
            {
                return(NotFound("Route not found."));
            }

            await _routeService.DeleteAsync(route);

            return(Ok());
        }
        public async Task <HttpResponseMessage> DeleteRoute(Guid id)
        {
            var response = await rService.DeleteAsync(id);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Beispiel #5
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            await _routeService.DeleteAsync(id);

            return(RedirectToAction(nameof(Index)));
        }