Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "EnterId,EnterName,Links,Category,CreatedDate,LastModifiedDate")] Entertainment et)
        {
            if (!ModelState.IsValid)
            {
                return(View("Error"));
            }

            _entertainmentUtil.AddEntertainment(et);

            return(RedirectToAction("Index", "Entertainment"));
        }
Exemplo n.º 2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            var et = new RememberUtility.Model.Entertainment();

            // txtEtName
            if (txtEtName.Text != "")
            {
                et.EnterName = txtEtName.Text.Trim();
            }
            else
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "et name cannot be null. Please choose a type";
            }

            // txtLink
            if (txtLink.Text != "")
            {
                et.Links = txtLink.Text.Trim();
            }
            else
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "Links cannot be null. Please choose a type";
            }

            // txtAuthorEnter
            if (txtAuthorEnter.Text != "")
            {
                et.AuthorEnter = txtAuthorEnter.Text.Trim();
            }
            else
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "Author Enter cannot be null. Please choose a type";
            }

            if (lstListEtCategory.SelectedIndex == -1)
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "Category aren't choose. Please choose a type";
            }

            if (txtLink.Text != "" && txtEtName.Text != "" && txtAuthorEnter.Text != "" && lstListEtCategory.SelectedIndex >= 0)
            {
                dynamic categoryInList = (lstListEtCategory.SelectedItem);
                string  catchCustom    = categoryInList as string;
                if (catchCustom.ToString() == CategoriesEntertainmentConstant.Custom)
                {
                    if (txtBtnCustomTextBox.Text == "")
                    {
                        AddEtResult.Foreground = Brushes.Red;
                        AddEtResult.Content    = "Category custom is emtpy. Please pick one.";
                        return;
                    }
                    else
                    {
                        et.Category = txtBtnCustomTextBox.Text;
                    }
                }
                else
                {
                    // use dynamic as type to cast your anonymous object to
                    categoryInList = (lstListEtCategory.SelectedItem);

                    // add category here
                    et.Category = categoryInList as string;
                }

                var findet = entertainmentUtil.FindEntertainmentBy(txtEtName.Text);
                if (findet != null)
                {
                    if (et.EnterName.ToLower() != findet.EnterName.ToLower())
                    {
                        entertainmentUtil.AddEntertainment(et);
                        AddEtResult.Foreground = Brushes.Green;

                        if (et.EnterName.Length <= 10)
                        {
                            AddEtResult.Content = $"Add '{et.EnterName}' Successful";
                        }
                        else
                        {
                            AddEtResult.Content = $"Add et Successful";
                        }

                        txtEtName.Text         = string.Empty;
                        txtLink.Text           = string.Empty;
                        txtAuthorEnter.Text    = string.Empty;
                        lstListEtCategory.Text = string.Empty;
                    }
                    else
                    {
                        AddEtResult.Foreground = Brushes.Red;
                        AddEtResult.Content    = $"'{txtEtName.Text}' duplicate. Add failed.";
                    }
                }
                else
                {
                    entertainmentUtil.AddEntertainment(et);
                    AddEtResult.Foreground = Brushes.Green;
                    AddEtResult.Content    = "Add et Successful";

                    txtEtName.Text         = string.Empty;
                    txtLink.Text           = string.Empty;
                    txtAuthorEnter.Text    = string.Empty;
                    lstListEtCategory.Text = string.Empty;
                }
            }
        }