Exemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] File item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var parent = _folderRepository.Find(item.ParentID);

            if (parent == null)
            {
                return(BadRequest());
            }

            var userId = _userManager.GetUserId(HttpContext.User);

            if (!_permissionServices.HasWriteAccess(parent.ProjectID, userId))
            {
                return(Unauthorized());
            }
            else
            {
                _fileRepository.Add(item);
                await _fileHandler.Add(item.Id, item.Name, item.Content, item.Syntax, item.ParentID, parent.ProjectID);

                return(CreatedAtAction("GetFile", new { id = item.Id }, item));
            }
        }
Exemplo n.º 2
0
        public ActionResult ChangeProfilePicture(HttpPostedFileBase upload)
        {
            if (upload != null && upload.ContentLength > 0)
            {
                var avatar = new FileEntity
                {
                    FileName      = System.IO.Path.GetFileName(upload.FileName),
                    FileType      = FileType.Avatar,
                    ContentType   = upload.ContentType,
                    UserProfileId = (int)Session["userProfileId"]
                };

                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    avatar.Content = reader.ReadBytes(upload.ContentLength);
                }

                var fileHandler = new FileHandler();
                var response    = fileHandler.GetAvatarForUserProfileId((int)Session["userProfileId"]);

                if (!response.CompletedRequest)
                {
                    return(RedirectToAction("Index", "Error", new { errorMessage = response.ErrorMessage.Replace(' ', '-') }));
                }

                if (response.Entity == null)
                {
                    response = fileHandler.Add(avatar);
                    if (!response.CompletedRequest)
                    {
                        return(RedirectToAction("Index", "Error", new { errorMessage = response.ErrorMessage.Replace(' ', '-') }));
                    }
                    else
                    {
                        return(RedirectToAction("UserProfile", "Account"));
                    }
                }

                avatar.FileId = response.Entity.FileId;
                response      = fileHandler.Update(avatar);

                if (!response.CompletedRequest)
                {
                    return(RedirectToAction("Index", "Error", new { errorMessage = response.ErrorMessage.Replace(' ', '-') }));
                }

                return(RedirectToAction("UserProfile", "Account"));
            }

            ViewBag.FileMessage = MessageConstants.NoFileSelected;
            return(View("ChangeProfilePicture"));
        }
Exemplo n.º 3
0
        public IWatcher GetWatcher()
        {
            string outputPath  = ConfigurationManager.AppSettings["OutputPath"];
            string pathToWatch = ConfigurationManager.AppSettings["ObservableDirectory"];

            if (string.IsNullOrWhiteSpace(outputPath))
            {
                throw new ArgumentException("В файле конфигурации не задан параметр OutputPath");
            }

            if (string.IsNullOrWhiteSpace(pathToWatch))
            {
                throw new ArgumentException("В файле конфигурации не задан ObservableDirectory");
            }

            TryAccsess(outputPath);

            var output         = new FileOutput(outputPath);
            var watcher        = new CommonWatcher(pathToWatch);
            var httpHandler    = new FileHandler(".html");
            var cssHandler     = new FileHandler(".css");
            var defaultHandler = new DefaultFileHandler();

            httpHandler.Add(new DivCounter());
            httpHandler.HandleComplete += output.Write;

            defaultHandler.Add(new PunctuationCounter());
            defaultHandler.HandleComplete += output.Write;

            cssHandler.Add(
                new BraceChecker(
                    new Dictionary <char, char> {
                { '}', '{' }
            }));
            cssHandler.HandleComplete += output.Write;

            watcher.AddHandler(httpHandler);
            watcher.AddHandler(cssHandler);
            watcher.DefaultHandler = defaultHandler;

            return(watcher);
        }
Exemplo n.º 4
0
        public ActionResult AddGalleryPicture(HttpPostedFileBase upload)
        {
            try
            {
                LoginHelper.CheckAccess(Session);
            }
            catch (Exception)
            {
                return(RedirectToAction("Login", "Login"));
            }

            if (upload != null && upload.ContentLength > 0)
            {
                var pic = new FileEntity
                {
                    FileName      = System.IO.Path.GetFileName(upload.FileName),
                    FileType      = FileType.Gallery,
                    ContentType   = upload.ContentType,
                    UserProfileId = (int)Session["userProfileId"]
                };

                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    pic.Content = reader.ReadBytes(upload.ContentLength);
                }

                var fileHandler = new FileHandler();
                var response    = fileHandler.Add(pic);

                if (!response.CompletedRequest)
                {
                    return(RedirectToAction("Index", "Error", new { errorMessage = response.ErrorMessage.Replace(' ', '-') }));
                }

                return(RedirectToAction("UserProfile", "Account"));
            }

            ViewBag.FileMessage = MessageConstants.NoFileSelected;
            return(View("AddGalleryPicture"));
        }