Example #1
0
        public async Task <IActionResult> Edit(CreateGoodModel createGoodModel)
        {
            if (ModelState.IsValid)
            {
                //var good = await _goodsRepository.GetAsync(createGoodModel.Id);
                var name       = User.Identity.Name;
                var loggedUser = await _adminRepository.GetByEmailAsync(name);

                string pathToPhoto = null;
                if (createGoodModel.UploadedFile != null)
                {
                    pathToPhoto = await SaveFile(createGoodModel.UploadedFile);
                }

                await _goodsRepository.UpdateAsync(new Good
                {
                    Id              = createGoodModel.Id,
                    Title           = createGoodModel.Title,
                    AdminId         = loggedUser.Id,
                    CreatedAt       = DateTime.UtcNow,
                    CategoryId      = createGoodModel.CategoryId,
                    Cost            = createGoodModel.Cost,
                    RealCost        = createGoodModel.RealCost,
                    ImagePath       = pathToPhoto ?? createGoodModel.DBPathFile,
                    Description     = createGoodModel.Description,
                    PromoCategoryId = createGoodModel.PromoCategoryId,
                    IsAutoIssuance  = createGoodModel.IsAutoGetting,
                });

                return(RedirectToAction("GoodIndex", "Shop"));
            }

            return(View(createGoodModel));
        }
        public object CreateGood([FromBody] CreateGoodModel cm)
        {
            try
            {
                var addr = Server.GetUserIp(Request.HttpContext);
                if (Server.IpHandle(addr) == 0)
                {
                    return(new[] { "your ip can't using our api , please contact administrator" });
                }

                var account = HttpContext.Session.GetString("user_account");

                if (account == null)
                {
                    return(new
                    {
                        result = 401,
                        msg = "not login"
                    });
                }

                var re = GoodServer.CreateGood(cm);

                return(re);
            }
            catch (Exception e)
            {
                return(new
                {
                    result = e.HResult,
                    msg = e.Message
                });
            }
        }
Example #3
0
        public async Task <IActionResult> Create()
        {
            var items = await CreateCategoryItems();

            var model = new CreateGoodModel {
                Categories = items
            };

            return(View(model));
        }
Example #4
0
        public async Task <IActionResult> Edit(int id)
        {
            var good = await _goodsRepository.GetAsync(id);

            var categories = await _categoryRepository.GetListAsync();

            var categoriesItem = new List <SelectListItem>();

            categories.ForEach(p => categoriesItem.Add(
                                   new SelectListItem
            {
                Text  = p.Position,
                Value = p.Id.ToString()
            }
                                   ));

            var promoCategories = await _promoCategoryRepository.GetListAsync();

            var promoCategoriesItem = new List <SelectListItem>();

            promoCategories.ForEach(p => promoCategoriesItem.Add(
                                        new SelectListItem
            {
                Text  = p.Name,
                Value = p.Id.ToString()
            }
                                        ));

            promoCategoriesItem.Insert(0, new SelectListItem
            {
                Text  = "",
                Value = "0",
            });

            var model = new CreateGoodModel {
                Categories      = categoriesItem,
                CategoryId      = good.CategoryId,
                PromoCategories = promoCategoriesItem,
                PromoCategoryId = good.PromoCategoryId.HasValue ? good.PromoCategoryId.Value : 0,
                Cost            = good.Cost,
                RealCost        = good.RealCost,
                Description     = good.Description,
                Title           = good.Title,
                DBPathFile      = good.ImagePath,
                Id            = good.Id,
                IsAutoGetting = good.IsAutoIssuance,
            };

            return(View(model));
        }
Example #5
0
        public async Task <IActionResult> Create(CreateGoodModel createGoodModel)
        {
            if (ModelState.IsValid)
            {
                var name       = User.Identity.Name;
                var loggedUser = await _adminRepository.GetByEmailAsync(name);

                string pathToPhoto = null;
                if (createGoodModel.UploadedFile != null)
                {
                    pathToPhoto = await SaveFile(createGoodModel.UploadedFile);
                }
                else
                {
                    ModelState.AddModelError("UploadedFile", "Не указан файл");
                }

                if (ModelState.IsValid)
                {
                    await _goodsRepository.AddAsync(new DomainLayer.Entities.Good
                    {
                        Title       = createGoodModel.Title,
                        AdminId     = loggedUser.Id,
                        CreatedAt   = DateTime.UtcNow,
                        CategoryId  = createGoodModel.CategoryId,
                        Cost        = createGoodModel.Cost,
                        RealCost    = createGoodModel.RealCost,
                        ImagePath   = pathToPhoto,
                        Description = createGoodModel.Description
                    });

                    return(RedirectToAction("GoodIndex", "Shop"));
                }

                var items = await CreateCategoryItems();

                createGoodModel.Categories = items;
            }

            return(View(createGoodModel));
        }
        /// <summary>
        /// 上架商品
        /// </summary>
        /// <param name="cm"></param>
        /// <returns></returns>
        public static object CreateGood(CreateGoodModel cm)
        {
            using (var con = new SqlConnection(Server.SqlConString))
            {
                con.Open();

                var sqlCom = new SqlCommand("sp_CreateGood", con)
                {
                    CommandType = CommandType.StoredProcedure
                };

                sqlCom.Parameters.AddRange(new[]
                {
                    new SqlParameter
                    {
                        ParameterName = "@programmeId",
                        Direction     = ParameterDirection.Input,
                        SqlDbType     = SqlDbType.Int,
                        Value         = cm.ProgrammeId
                    },
                    new SqlParameter
                    {
                        ParameterName = "@theaterId",
                        Direction     = ParameterDirection.Input,
                        SqlDbType     = SqlDbType.Int,
                        Value         = cm.TheaterId
                    },
                    new SqlParameter
                    {
                        ParameterName = "@performance",
                        Direction     = ParameterDirection.Input,
                        Size          = 10,
                        SqlDbType     = SqlDbType.NVarChar,
                        Value         = cm.Performance
                    },
                    new SqlParameter
                    {
                        ParameterName = "@playDate",
                        Direction     = ParameterDirection.Input,
                        SqlDbType     = SqlDbType.Date,
                        Value         = cm.PlayDate
                    },
                    new SqlParameter
                    {
                        ParameterName = "@price",
                        Direction     = ParameterDirection.Input,
                        SqlDbType     = SqlDbType.Int,
                        Value         = cm.Price
                    },
                    new SqlParameter
                    {
                        ParameterName = "@message",
                        Direction     = ParameterDirection.Output,
                        Size          = 30,
                        SqlDbType     = SqlDbType.VarChar
                    },
                    new SqlParameter
                    {
                        ParameterName = "@return",
                        Direction     = ParameterDirection.ReturnValue,
                        SqlDbType     = SqlDbType.Int
                    }
                });

                sqlCom.ExecuteNonQuery();

                return(new
                {
                    result = (int)sqlCom.Parameters["@return"].Value,
                    msg = (string)sqlCom.Parameters["@message"].Value
                });
            }
        }