Ejemplo n.º 1
0
        public ActionResult Create()
        {
            ProjectWithDepartmentViewModel view = new ProjectWithDepartmentViewModel();
            view.Departments = Facade.GetDepartmentGateway().ReadAll();
            view.Project = new ProjectViewModel();

            return View(view);
        }
Ejemplo n.º 2
0
        public ActionResult Create(ProjectViewModel project)
        {
            ProjectWithDepartmentViewModel view = new ProjectWithDepartmentViewModel();
            view.Departments = Facade.GetDepartmentGateway().ReadAll();
            view.Project = project;

            if (project.Image.ContentLength > (2 * 1024 * 1024))
            {
                ModelState.AddModelError("CustomError", "Filen skal være mindre end 2 MB");
                return View(view);
            }

            if (!(project.Image.ContentType == "image/jpeg" || project.Image.ContentType == "image/gif"))
            {
                ModelState.AddModelError("CustomError", "Tillate fil typer jpeg og gif");
                return View(view);
            }

            if (ModelState.IsValid)
            {
                byte[] data = new byte[project.Image.ContentLength];
                project.Image.InputStream.Read(data, 0, project.Image.ContentLength);

                project.ImageData = data;

                Project newProject = new Project()
                {
                    Name = project.Name,
                    ImageData = project.ImageData,
                    DepartmentId = project.DepartmentId
                };

                Facade.GetProjectGateway().Create(newProject);
                return RedirectToAction("Index");
            }

            return View(view);
        }