Пример #1
0
        public ActionResult _Upload(UploadForm form)
        {
            if (ModelState.IsValid)
            {
                byte[] file = new byte[form.File.ContentLength];
                form.File.InputStream.Read(file, 0, file.Length);

                Document doc = new Document
                {
                    Filename       = Path.GetFileName(form.File.FileName),
                    Body           = file,
                    AuthorEmployee = SessionUser.GetUser().Id
                };
                if (form.PreviousVersionId.HasValue)
                {
                    doc.Id = form.PreviousVersionId;
                }
                int?DocumentId = DocumentService.Create(doc);
                if (DocumentId != null)
                {
                    if (form.DepartmentId != null)
                    {
                        DocumentService.AddToDepartment((int)DocumentId, (int)form.DepartmentId);
                        return(RedirectToAction("Details", "Department", new { id = form.DepartmentId }));
                    }
                    else if (form.EventId != null)
                    {
                        DocumentService.AddToEvent((int)DocumentId, (int)form.EventId);
                        return(RedirectToAction("Details", "Event", new { id = form.EventId }));
                    }
                    else if (form.MessageId != null)
                    {
                        DocumentService.AddToMessage((int)DocumentId, (int)form.MessageId);
                    }
                    else if (form.ProjectId != null)
                    {
                        DocumentService.AddToProject((int)DocumentId, (int)form.ProjectId);
                        return(RedirectToAction("Details", "Project", new { projectId = form.ProjectId }));
                    }
                    else if (form.TaskId != null)
                    {
                        DocumentService.AddToTask((int)DocumentId, (int)form.TaskId);
                        return(RedirectToAction("Details", "Task", new { taskId = form.TaskId }));
                    }
                    else if (form.TeamId != null)
                    {
                        DocumentService.AddToTeam((int)DocumentId, (int)form.TeamId);
                        return(RedirectToAction("Details", "Team", new { teamId = form.TeamId }));
                    }
                    else if (form.PreviousVersionId != null)
                    {
                        return(RedirectToAction("Details", "Document", new { id = form.PreviousVersionId }));
                    }
                }
            }
            return(RedirectToAction("Index", "Employee"));
        }