public IActionResult SaveChange(ProductConfig model)
        {
            string note   = AppGlobal.InitString;
            int    result = 0;

            if (model.Id > 0)
            {
                model.Initialization(InitType.Update, RequestUserID);
                result = _productConfigResposistory.Update(model.Id, model);
                if (result > 0)
                {
                    note = AppGlobal.Success + " - " + AppGlobal.EditSuccess;
                }
                else
                {
                    note = AppGlobal.Success + " - " + AppGlobal.EditFail;
                }
            }
            else
            {
                model.Initialization(InitType.Insert, RequestUserID);
                result = _productConfigResposistory.Create(model);
                if (result > 0)
                {
                    note = AppGlobal.Success + " - " + AppGlobal.CreateSuccess;
                }
                else
                {
                    note = AppGlobal.Success + " - " + AppGlobal.CreateFail;
                }
            }
            return(Json(note));
        }
Esempio n. 2
0
        public ActionResult <string> SaveChange(ProductConfig model)
        {
            Result routeResult;
            int    result = 0;

            if (model.Id > 0)
            {
                model.Initialization(InitType.Update, RequestUserID);
                result = _productConfigResposistory.Update(model.Id, model);

                if (result > 0)
                {
                    routeResult = new Result()
                                  .setResultType(ResultType.Success)
                                  .setMessage(AppGlobal.EditSuccess);
                }
                else
                {
                    routeResult = new Result()
                                  .setResultType(ResultType.Error)
                                  .setErrorType(ErrorType.EditError)
                                  .setMessage(AppGlobal.EditFail);
                }
            }
            else
            {
                model.Initialization(InitType.Insert, RequestUserID);
                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));
        }
        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));
        }
Esempio n. 4
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 }));
        }