예제 #1
0
        public async Task <IActionResult> Create(ClassCreateVM classVM, IFormFile uploadfile)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var model = new ClassCreateVM();
                    return(View(model));
                }

                string combineFileName = null;
                if (uploadfile != null)
                {
                    string fileName = Guid.NewGuid().ToString();
                    string fileType = System.IO.Path.GetExtension(uploadfile.FileName);
                    combineFileName = fileName + fileType;
                    classVM.Image   = combineFileName;

                    using (var localFile = System.IO.File.OpenWrite("Uploads/Class/" + combineFileName))
                        using (var uploadedFile = uploadfile.OpenReadStream())
                        {
                            uploadedFile.CopyTo(localFile);
                        }
                }

                ClassDTO classDTO = _mapper.Map <ClassDTO>(classVM);
                _classService.Add(classDTO);

                TempData["Statu"] = "ok";
                return(RedirectToAction("index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
예제 #2
0
        public ActionResult Create()
        {
            var model = new ClassCreateVM();

            return(View(model));
        }