Inheritance: System.Data.Objects.DataClasses.EntityObject
 public async static Task Update(m.Category obj)
 {
     using (var db = DbAccess.ConnectionFactory())
     {
         await db.ExecuteAsync(DbAccess.Update <m.Category>(), obj);
     }
 }
		public async Task EnsureSeedData()
		{
			if (await _userManager.FindByEmailAsync("*****@*****.**") == null)
			{
				// Add the user
				var newUser = new BlogUser()
				{
					UserName = "******",
					Email = "*****@*****.**"
				};

				await _userManager.CreateAsync(newUser, "123321");
			}

			if (!_contex.Categories.Any())
			{
				var category = new Category() {Name = "Main", Description = "Descr"};
				_contex.Categories.Add(category);

				var firstPost = new Post()
				{
					Category = category,
					Title = "First Post"
				};
				_contex.Posts.Add(firstPost);

				_contex.SaveChanges();
			}
		}
		public CategoryViewer(Category category)
		{
			Title = WindowTitle = "Category: " + category.Name;
			this.category = category;
			InitializeComponent();
			Header.DataContext = category;
			posts = new List<Post>(category.Posts);
			posts.Sort(delegate(Post x, Post y) { return x.Modified.CompareTo(y.Modified); });
			PostsView.ItemsSource = posts;
		}
 public ActionResult Edit(Category category)
 {
     if (SCategory.EditCategory(category))
         return View("Index", SCategory.GetAllCategories());
     else
     {
         ModelState.AddModelError("", "Validation Error");
         return View();
     }
 }
Esempio n. 5
0
 public bool AddCategory(Category category)
 {
     try
     {
         context.Category.Add(category);
         context.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
        public async Task <IActionResult> Post([FromBody] m.Category data)
        {
            try
            {
                await d.Category.Insert(data);

                return(Ok(data));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 7
0
 private void AddButtonClick(object sender, RoutedEventArgs e)
 {
     AddItemsWindow addItemsWindow = new AddItemsWindow();
     addItemsWindow.ShowDialog();
     using (var db = new Model.BudgetModel())
     {
         var category = new Category();
         if (string.IsNullOrWhiteSpace(addItemsWindow.Value)) MessageBox.Show("Введите название");
         else
         {
             category.Name = addItemsWindow.Value;
             db.Categories.Add(category);
             db.SaveChanges();
             UpdateListBox();
         }
     }
 }
Esempio n. 8
0
 public bool EditCategory(Category category)
 {
     try
     {
         var dbEntry = context.Category.Find(category.Id);
         if (dbEntry != null)
         {
             dbEntry.Name = category.Name;
         }
         context.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
        public async Task <IActionResult> Put(Guid id, [FromBody] m.Category data)
        {
            try
            {
                if (id != data.CategoryId)
                {
                    return(BadRequest());
                }

                await d.Category.Update(data);

                return(Ok(data));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 10
0
        IEnumerable<Category> MockCategories()
        {
            List<Category> CategoryList = new List<Category>();
            Category cat2 = new Category
            {
                Title = "Avfall & Återvinning",
                Source = "http://orebrokoll.azurewebsites.net/api/Categories/1"
            };

            Category cat = new Category
            {
                Title = "Resturanger",
                Source = "http://orebrokoll.azurewebsites.net/api/Categories/2"
            };
            CategoryList.Add(cat2);
            CategoryList.Add(cat);
            return CategoryList;
        }
Esempio n. 11
0
 private void categoryAddButtonClick(object sender, EventArgs e)
 {
     AddItemForm addItemForm = new AddItemForm();
     if(addItemForm.ShowDialog(this) == DialogResult.OK)
     {
         using (var db = new Model.BudgetModel())
         {
             var category = new Category();
             if (string.IsNullOrWhiteSpace(addItemForm.Value)) MessageBox.Show("Введите название");
             else
             {
                 category.Name = addItemForm.Value;
                 db.Categories.Add(category);
                 db.SaveChanges();
             }
         }
         UpdateListBox();
     }
 }
Esempio n. 12
0
        public List <Model.Category> GetCategory()
        {
            List <Model.Category> categoryList = new List <Model.Category>();
            SqlDataAdapter        da           = new SqlDataAdapter("select * from category", con);
            DataSet categoryset = new DataSet();

            da.Fill(categoryset, "Category");
            for (int i = 0; i < categoryset.Tables["Category"].Rows.Count; i++)
            {
                Model.Category c = new Model.Category();

                c.Cid     = int.Parse(categoryset.Tables["Category"].Rows[i][0].ToString());
                c.Cname   = categoryset.Tables["Category"].Rows[i][1].ToString();
                c.Cstatus = categoryset.Tables["Category"].Rows[i][2].ToString();
                categoryList.Add(c);
            }

            return(categoryList);
        }
Esempio n. 13
0
        /**
         *
         * 增加品牌
         *
         * */
        public bool addCategory(Category category)
        {
            try
            {
               // int brandId = this.findIdByColomn("brand","brand_name",category.getBrandName());

                string sql = "insert into category (category_name,net_rate,brand) values(@categoryName,@netRate,@brandId)";

                Dictionary<string, Object> parameters = new Dictionary<string, Object>();

                parameters.Add("@categoryName", category.getCategoryName());
                parameters.Add("@netRate", category.getNetRate());
                parameters.Add("@brandId", category.getBrandId());

                dbAccess.excute(sql, parameters);
                return true;
            }
            catch (Exception e)
            {
                throw new MyException(e.Message);
            }
        }
Esempio n. 14
0
        /**
         *
         * 查询所有品牌
         *
         * */
        public List<Category> findCategorys()
        {
            SqlCeDataReader dr = null;

            List<Category> categorys = new List<Category>();

            try
            {
                string sql = "select a.id, a.category_name, a.net_rate, b.brand_name, a.brand from category a , brand b where a.brand = b.id";

                dr = dbAccess.excuteSqlCeQuery(sql);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        Category category = new Category();

                        category.Id = dr.GetInt32(0);

                        if (dr.IsDBNull(1))
                            category.setCategoryName("");
                        else
                            category.setCategoryName(dr.GetString(1));

                        if (dr.IsDBNull(2))
                            category.setNetRate(float.NaN);
                        else
                            category.setNetRate((float)dr.GetDouble(2));

                        if (dr.IsDBNull(3))
                            category.setBrandName("");
                        else
                            category.setBrandName(dr.GetString(3));

                        category.setBrandId(dr.GetInt32(4));

                        categorys.Add(category);
                    }
                }
            }
            catch (Exception e)
            {
                throw new MyException(e.Message);
            }
            finally
            {
                if (null != dr)
                    dr.Close();
            }

            return categorys;
        }
Esempio n. 15
0
        /**
         *
         * 更新品牌
         *
         * */
        public bool updateCategory(Category Category)
        {
            try
            {
                string sql = "update category set category_name = @categoryName, net_rate = @netRate, brand = @brandId where id = @id";

                Dictionary<string, Object> parameters = new Dictionary<string, Object>();

                parameters.Add("@categoryName", Category.getCategoryName());
                parameters.Add("@netRate", Category.getNetRate());
                parameters.Add("@brandId", Category.getBrandId());
                parameters.Add("@id", Category.Id);

                dbAccess.excute(sql, parameters);
                return true;
            }
            catch (Exception e)
            {
                throw new MyException(e.Message);
            }
        }
Esempio n. 16
0
 public void setCategory(Category category)
 {
     this.category = category;
 }
Esempio n. 17
0
 partial void UpdateCategory(Category instance);
        private void updateButton_Click(object sender, EventArgs e)
        {
            ListViewItem item = this.categoryListView.FocusedItem;
            if (null != item)
            {
                CategoryForm categoryForm = new CategoryForm();

                Category category = new Category(item.SubItems[1].Text,float.Parse(item.SubItems[2].Text),int.Parse(item.SubItems[4].Text));
                category.Id = Int32.Parse(item.SubItems[0].Text);

                categoryForm.setCategory(category);
                categoryForm.init();

                categoryForm.setFlag("update");

                if (categoryForm.ShowDialog() == DialogResult.OK)
                {
                    initListView();
                }
            }
            else
            {
                MessageBox.Show("请先选择类别!");
            }
        }
Esempio n. 19
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(Category category)
 {
     base.AddObject("Categories", category);
 }
Esempio n. 20
0
 partial void InsertCategory(Category instance);
Esempio n. 21
0
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String name)
 {
     Category category = new Category();
     category.Id = id;
     category.Name = name;
     return category;
 }
Esempio n. 22
0
 partial void DeleteCategory(Category instance);
Esempio n. 23
0
		private static IList<Post> ProcessDayEntry(string file, IDictionary<string, Category> categories)
		{
			IList<Post> posts = new List<Post>();
			XmlDocument xdoc = GetXmlDocument(file);
			XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xdoc.NameTable);
			namespaceManager.AddNamespace("das", "urn:newtelligence-com:dasblog:runtime:data");
			foreach (XmlNode node in xdoc.SelectNodes("/das:DayEntry/das:Entries/das:Entry", namespaceManager))
			{
				Xml xml = new Xml(node, namespaceManager);
				Post post = new Post();
				post.Title = xml.GetString("das:Title/text()");
				post.Created = xml.GetDate("das:Created/text()");
				post.Modified = xml.GetDate("das:Modified/text()");
				post.Content = xml.GetString("das:Content/text()");
				post.PostId = xml.GetGuid("das:EntryId/text()");
				string[] categoriesNames = xml.GetString("das:Categories/text()")
					.Split(new string[]{";"},StringSplitOptions.RemoveEmptyEntries);
				foreach (string name in categoriesNames)
				{
					if (categories.ContainsKey(name) == false)
					{
						categories[name] = new Category(name);
					}
					post.AddToCategory(categories[name]);
				}
				posts.Add(post);
			}
			return posts;
		}