Пример #1
0
        public IActionResult CreatePicture(NewPictureInputModel model)
        {
            if (ModelState.IsValid)
            {
                var uploads = Path.Combine(Directory.GetCurrentDirectory(), "Uploads");

                if (model.File.Length > 0)
                {
                    var path = Path.Combine(uploads, model.File.FileName);
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        //Create file
                        model.File.CopyTo(fileStream);

                        picturesService.AddPicture(model.Name, model.File.FileName);

                        string content = string.Format("{0} uploaded photo: {1}", GetCurrentUserName(User.GetUserId()), model.Name);
                        logsService.AddNewLog("Create", content);

                        return(RedirectToAction("ViewPictures"));
                    }
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }