Ejemplo n.º 1
0
        public async Task <Result <Post> > Handle(CreatePostCommand request, CancellationToken cancellationToken)
        {
            Result <PostTitle> postTitleOrError = PostTitle.Create(request.Title);

            if (postTitleOrError.IsFailure)
            {
                return(Result.Failure <Post>(postTitleOrError.Error));
            }

            var post = new Post(postTitleOrError.Value, request.CreationDate, request.Content);
            await repo.Save(post);

            var pst = await repo.GetAll();

            return(Result.Ok(pst.LastOrDefault()));
        }
Ejemplo n.º 2
0
 public Post(PostTitle posttitle, DateTime?dateOfCreation, string content)
 {
     Title        = posttitle ?? throw new ArgumentNullException(nameof(posttitle));
     CreationDate = dateOfCreation ?? throw new ArgumentNullException(nameof(content));
     Content      = content ?? throw new ArgumentNullException(nameof(content));
 }
Ejemplo n.º 3
0
 public string GetTitleAsUrl()
 {
     return(PostTitle.Trim().ToLower().Replace(" ", "-").Replace(".", "").Replace(",", ""));
 }
Ejemplo n.º 4
0
 public string GetPostTitleText()
 {
     return(PostTitle.GetAttribute("value"));
 }
Ejemplo n.º 5
0
 public void SetPostTitleText(string text)
 {
     PostTitle.Clear();
     PostTitle.SendKeys(text);
 }
Ejemplo n.º 6
0
    protected void BAddCategory_Click(object sender, EventArgs e)
    {
        TextBox TBCN          = (TextBox)LoginView1.FindControl("TBCategoryName");
        string  _categoryName = TBCN.Text;
        string  queryString   = "SELECT [title], [titleID] FROM [Title] WHERE title = @title_p";

        Label LResult = (Label)LoginView1.FindControl("LResult");

        if (_categoryName == "")
        {
            LResult.Text = "Empty category name is proxibited.";
            return;
        }

        SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\mydb.mdf;Integrated Security=True");

        string _resultUserId;

        string[] allRecords;

        using (var command = new SqlCommand(queryString, connection))
        {
            command.Parameters.Add("@title_p", SqlDbType.NVarChar).Value = _categoryName;
            connection.Open();
            using (var reader = command.ExecuteReader())
            {
                var list = new List <string>();
                while (reader.Read())
                {
                    list.Add(reader.GetSqlValue(0).ToString());
                }
                allRecords = list.ToArray();
            }
        }

        if (allRecords.Length == 1)
        {
            // Error: User category with such name already exists !
            LResult.Text = "Error: Category with such name already exists ! ";
            return;
        }
        else
        if (allRecords.Length == 0)
        {
            // It's ok, let's add this category to the Database

            try
            {
                PostTitle.insertTitle(_categoryName);
                LResult.Text = "Category added succesfully.";
                TBCN.Text    = "";
                Response.Redirect("ManageCategories.aspx");
            }
            catch (Exception ex)
            {
                LResult.Text = "Exception: " + ex.ToString();
            }
        }
        else
        if (allRecords.Length >= 1)
        {
            // THis should not happen
            LResult.Text = "ERROR: More categories with such names exists 1";
            return;
        }
    }