Esempio n. 1
0
 public static int CreateCategory(Category category)
 {
     const string sql = "insert into Category(Name,Description,CreateTime,CreateUser,EnumDataEntityStatus,MergedId) values(@Name,@Description,@CreateTime,@CreateUser,@EnumDataEntityStatus,@MergedId);Select LAST_INSERT_ID();";
     MySqlCommand command = new MySqlCommand(sql, ProductMySqlConnection);
     command.Parameters.AddWithValue("@Name", category.Name);
     command.Parameters.AddWithValue("@Description", category.Description);
     command.Parameters.AddWithValue("@CreateTime", category.CreateTime);
     command.Parameters.AddWithValue("@CreateUser", category.CreateUser);
     command.Parameters.AddWithValue("@EnumDataEntityStatus", category.EnumDataEntityStatus);
     command.Parameters.AddWithValue("@MergedId", category.MergedId);
     ProductMySqlConnection.Open();
     Int32 categoryId = Convert.ToInt32(command.ExecuteScalar());
     return categoryId;
 }
Esempio n. 2
0
        public static List<Category> SearchCategoryByName(string name)
        {
            List<Category> categories = new List<Category>();
            const string sql = "SELECT * FROM Category WHERE Name=@Name";
            MySqlCommand command = new MySqlCommand(sql, ProductMySqlConnection);
            command.Parameters.AddWithValue("@Name",name);
            ProductMySqlConnection.Open();
            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                Category category = new Category();
                category.CategoryId = reader.GetInt32("CategoryId");
                category.CreateTime = reader.GetDateTime("CreateTime");
                category.CreateUser = reader.GetInt32("CreateUser");
                category.Description = reader.GetString("Description");
                category.EnumDataEntityStatus = (EnumDataEntityStatus)reader.GetInt32("EnumDataEntityStatus");
                category.MergedId = reader.GetInt32("MergedId");
                category.Name = reader.GetString("Name");
                categories.Add(category);

            }
            return categories;
        }
Esempio n. 3
0
        public static Category GetCategoryById(int categoryId)
        {
            const string sql = "SELECT top 1 * FROM Category WHERE CategoryId=@CategoryId";
            MySqlCommand command = new MySqlCommand(sql, ProductMySqlConnection);
            command.Parameters.AddWithValue("@CategoryId", categoryId);
            ProductMySqlConnection.Open();
            var reader = command.ExecuteReader();
            if (reader.Read())
            {
                Category category = new Category();
                category.CategoryId = reader.GetInt32("CategoryId");
                category.CreateTime = reader.GetDateTime("CreateTime");
                category.CreateUser = reader.GetInt32("CreateUser");
                category.Description = reader.GetString("Description");
                category.EnumDataEntityStatus = (EnumDataEntityStatus) reader.GetInt32("EnumDataEntityStatus");
                category.MergedId = reader.GetInt32("MergedId");
                category.Name = reader.GetString("Name");
                return category;

            }

            return null;
        }
        public ActionResult Add(StuffCommentCreateViewModel viewModel)
        {
            int userId;
            int.TryParse(TicketTool.GetUserData(), out userId);

            // 如无Category,创建新的
            if (viewModel.CategoryId == 0)
            {
                // 搜索
                var categories = StuffManager.SearchCategoryByName(viewModel.CategoryName.Trim());
                if (categories.Any(m => m.EnumDataEntityStatus == EnumDataEntityStatus.Normal))
                {
                    viewModel.CategoryId = categories.First(m => m.EnumDataEntityStatus == EnumDataEntityStatus.Normal).CategoryId;
                }
                else
                {
                    Category category = new Category();
                    //category.CategoryId
                    category.CreateTime = DateTime.Now;
                    category.CreateUser = userId;
                    category.Description = "";
                    category.EnumDataEntityStatus = EnumDataEntityStatus.Normal;
                    category.MergedId = 0;
                    category.Name = viewModel.CategoryName;
                    int categoryId = StuffManager.CreateCategory(category);
                    viewModel.CategoryId = categoryId;
                }


            }

            // 如无Brand,创建新的
            if (viewModel.BrandId == 0)
            {
                var brands = StuffManager.SearchBrandByName(viewModel.CategoryName.Trim());
                if (brands != null && brands.Any(m => m.EnumDataEntityStatus == EnumDataEntityStatus.Normal))
                {
                    viewModel.BrandId = brands.First(m => m.EnumDataEntityStatus == EnumDataEntityStatus.Normal).BrandId;
                }
                else
                {

                    Brand brand = new Brand();
                    brand.CreateTime = DateTime.Now;
                    brand.CreateUser = userId;
                    brand.Description = "";
                    brand.EnumDataEntityStatus = EnumDataEntityStatus.Normal;
                    brand.MergedId = 0;
                    brand.Name = viewModel.BrandName;
                    int brandId = StuffManager.CreateBrand(brand);
                    viewModel.BrandId = brandId;
                }


            }

            // 如无产品,创建新的
            if (viewModel.StuffId == 0)
            {
                var stuffs = StuffManager.SearchStuffByName(viewModel.StuffName);
                if (stuffs != null && stuffs.Any(m => m.EnumDataEntityStatus == EnumDataEntityStatus.Normal))
                {
                    viewModel.StuffId = stuffs.First(m => m.EnumDataEntityStatus == EnumDataEntityStatus.Normal).StuffId;
                }
                else
                {
                    Stuff stuff = new Stuff();
                    stuff.BrandId = viewModel.BrandId;
                    stuff.CategoryId = viewModel.CategoryId;
                    stuff.CraeteTime = DateTime.Now;
                    stuff.CreateUser = userId;
                    stuff.EnumDataEntityStatus = EnumDataEntityStatus.Normal;
                    stuff.MergedId = 0;
                    stuff.Name = viewModel.StuffName.Trim();
                    int stuffId =StuffManager.CreateStuff(stuff);
                    viewModel.StuffId = stuffId;

                }


            }

            // 创建评论
            StuffComment stuffComment = new StuffComment();

            stuffComment.BuyPrice = viewModel.BuyPrice;
            stuffComment.CommentDetail = viewModel.CommentDetail;
            stuffComment.CostPerformance = viewModel.CostPerformance;
            stuffComment.CrateTime = DateTime.Now;

            stuffComment.CreateUser = userId;
            stuffComment.EnumAuditStatus = EnumAuditStatus.Approved;
            stuffComment.Functions = viewModel.Functions;
            stuffComment.IsActive = true;
            // TODO:图片数据需要再处理
            stuffComment.Pictures = new List<string>();
            stuffComment.PublishTime = DateTime.Now;
            stuffComment.Published = true;
            stuffComment.Service = viewModel.Service;
            //stuffComment.StuffCommentId
            stuffComment.StuffId = viewModel.StuffId;
            stuffComment.Workmanship = viewModel.Workmanship;

            int stuffCommentId = StuffManager.CreateStuffComment(stuffComment);

            return View();
        }