Exemplo n.º 1
0
 public void CategoryListView_InsertItem(Category category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Service.UpdateCategory(category);
         }
         catch (Exception)
         {
             ModelState.AddModelError(String.Empty, "Ett oväntat fel inträffade då kategoriuppgiften skulle läggas till.");
         }
     }
 }
Exemplo n.º 2
0
 public void CategoryListView_InsertItem(Category category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Service.UpdateCategory(category);
             //Session["Success"] = true;
             //Response.RedirectToRoute("Default");
         }
         catch (Exception)
         {
             ModelState.AddModelError(String.Empty, "Ett oväntat fel inträffade då kategoriuppgiften skulle läggas till.");
         }
     }
 }
Exemplo n.º 3
0
        public void UpdateCategory(Category category)
        {

            ICollection<ValidationResult> validationResults;
            if (!category.Validate(out validationResults))
            {
                var ex = new ValidationException("Objektet klarade inte valideringen.");
                ex.Data.Add("ValidationResults", validationResults);
                throw ex;
            }
            if (category.CategoryID == 0) // New post if ID is 0!
            {
                CategoryDAL.InsertCategory(category);
            }
            else
            {
                CategoryDAL.UpdateCategory(category);
            }

        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates category
        /// </summary>
        /// <param name="category"></param>
        public void UpdateCategory(Category category)
        {
            using (SqlConnection conn = CreateConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("appSchema.uspUpdateCategory", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    conn.Open();
                    cmd.Parameters.Add("@CategoryID", SqlDbType.Int, 4).Value = category.CategoryID;
                    cmd.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 20).Value = category.CategoryName;
                    cmd.ExecuteNonQuery();

                }
                catch
                {
                    throw new ApplicationException("An error occured in the data access layer.");
                }
            }
        }