예제 #1
0
 private static void Interpreter_OnDeleteUser(string UserName)
 {
     try
     {
         System.Console.WriteLine(string.Format("User '{0}' will be deleted", UserName));
         System.Console.WriteLine("You are shure? Y/N");
         ConsoleKeyInfo keyInfo = System.Console.ReadKey();
         do
         {
             System.Console.WriteLine("Pleas enter 'Y' for 'yes' or 'N' for 'no'");
             keyInfo = System.Console.ReadKey();
             if (keyInfo.Key == ConsoleKey.Y)
             {
                 Admins.Delete(UserName);
             }
             if (keyInfo.Key == ConsoleKey.Y)
             {
                 return;
             }
         }while (keyInfo.Key != ConsoleKey.Y && keyInfo.Key != ConsoleKey.N);
     }
     catch (KeyNotFoundException ex)
     {
         System.Console.WriteLine("  User not found");
     }
     catch (Exception ex)
     {
         System.Console.WriteLine($"Delete user error: {ex}");
         Logger.Error(ex, "Delete user error");
     }
 }
 public void delete_admin()
 {
     Init();
     // TEST: add new Admins without email to db
     Admins.Add(item_enabled);
     Admins.Delete(item_enabled.Email);
     Assert.AreEqual(Admins.All().Count, 0);
 }
 public void delete_not_exists_admin()
 {
     Init();
     // TEST: add new Admins without email to db
     Assert.ThrowsException <KeyNotFoundException>(() =>
     {
         Admins.Delete("not_exist_user");
     });
 }
예제 #4
0
        public JsonResult delete([FromBody] string content)
        {
            try
            {
                Logger.Trace("AdminsController.delete IN");
                HttpRequest Request = ControllerContext.HttpContext.Request;

                if (!Request.ContentType.Contains("application/json"))
                {
                    return(new JsonResult(ResponseData.CONFLICT_409("Wrong content type. Content type must be 'application/json'"))
                    {
                        StatusCode = (int)System.Net.HttpStatusCode.Conflict
                    });
                }
                if (Request.Body.Length > 1000)
                {
                    return(new JsonResult(ResponseData.CONFLICT_409("Big content. The data length must be less than 1000"))
                    {
                        StatusCode = (int)System.Net.HttpStatusCode.Conflict
                    });
                }



                RequestData requestData = RequestData.Deserialize(Request.Body);
                string      Email       = requestData.GetValue("email") as string;
                Logger.Debug($"AdminsController.delete Email = {Email}");
                Admins.Delete(Email, db);
                Logger.Debug("AdminsController.delete deleted");
                return(new JsonResult(ResponseData.OK_200())
                {
                    StatusCode = (int)System.Net.HttpStatusCode.OK
                });
            }
            catch (ValidationException ex)
            {
                Logger.Error(ex, "Error in Admins.delete: ValidateError");
                return(new JsonResult(ResponseData.CONFLICT_409(ex.Message))
                {
                    StatusCode = (int)System.Net.HttpStatusCode.Conflict
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error in Admins.delete");
                return(new JsonResult(ResponseData.INTERNAL_SERVER_ERROR_500())
                {
                    StatusCode = (int)System.Net.HttpStatusCode.InternalServerError
                });
            }
            finally
            {
                Logger.Trace("AdminsController.delete OUT");
            }
        }