public IActionResult Create(ProductConfig model)
        {
            string note = AppGlobal.InitString;

            model.Initialization(InitType.Insert, RequestUserID);
            int result = _productConfigResposistory.Create(model);

            if (result > 0)
            {
                note = AppGlobal.Success + " - " + AppGlobal.CreateSuccess;
            }
            else
            {
                note = AppGlobal.Success + " - " + AppGlobal.CreateFail;
            }
            return(Json(note));
        }
Exemple #2
0
        public ActionResult <string> Create(ProductConfig model)
        {
            Result routeResult;

            model.Initialization(InitType.Insert, RequestUserID);
            int result = _productConfigResposistory.Create(model);

            if (result > 0)
            {
                routeResult = new Result()
                              .setResultType(ResultType.Success)
                              .setMessage(AppGlobal.CreateSuccess);
            }
            else
            {
                routeResult = new Result()
                              .setResultType(ResultType.Error)
                              .setErrorType(ErrorType.InsertError)
                              .setMessage(AppGlobal.CreateFail);
            }

            return(ObjectToJson(routeResult));
        }
Exemple #3
0
        public IActionResult SaveFiles(Product model)
        {
            if (Request.Form.Files.Count > 0)
            {
                List <ProductConfig> list = new List <ProductConfig>();
                for (int i = 0; i < Request.Form.Files.Count; i++)
                {
                    var file = Request.Form.Files[i];
                    if (file != null)
                    {
                        string fileExtension = Path.GetExtension(file.FileName);
                        string fileName      = Path.GetFileNameWithoutExtension(file.FileName);

                        fileName = AppGlobal.SetName(fileName);
                        fileName = model.ID + "-" + fileName + "-" + AppGlobal.DateTimeCode + fileExtension;
                        var physicalPath = Path.Combine(_hostingEnvironment.WebRootPath, AppGlobal.URLProduct, fileName);
                        using (var stream = new FileStream(physicalPath, FileMode.Create))
                        {
                            file.CopyTo(stream);
                            ProductConfig productConfig = new ProductConfig();
                            productConfig.Initialization(InitType.Insert, RequestUserID);
                            productConfig.ParentID = model.ID;
                            productConfig.Title    = model.Title;
                            productConfig.FileName = fileName;
                            productConfig.URL      = AppGlobal.Domain + AppGlobal.URLProduct + "/" + fileName;
                            productConfig.Note     = fileExtension;
                            try
                            {
                                _productConfigRepository.Create(productConfig);
                            }
                            catch (Exception e)
                            {
                                string mes = e.Message;
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("DetailFiles", "Product", new { ID = model.ID }));
        }