Ejemplo n.º 1
0
        public ActionResult UploadTempProjectIcon(HttpPostedFileBase file, int tempProjectId)
        {
            string error = "";

            _db = new ApplicationDbContext();
            var project = (from u in _db.TempProjects where u.TempProjectId == tempProjectId select u).First();

            var img = System.Drawing.Image.FromStream(file.InputStream, true, true);

            if (img.Width > 150 || img.Height > 150)
            {
                error = "Maksymalny rozmiar ikony to 150x150px.";
            }
            if (img.Width < 50 || img.Height < 50)
            {
                error = "Minimalny rozmiar ikony to 50x50px.";
            }

            file.InputStream.Seek(0, SeekOrigin.Begin);

            if (file.ContentLength > 0 && string.IsNullOrEmpty(error))
            {
                BlobConnector.UploadIcon(file, tempProjectId, false);
                project.IsIcon           = true;
                _db.Entry(project).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
            }
            else
            {
                error = "Błąd wgrywania pliku";
            }


            return(RedirectToAction("CreateTempProjectView2", new { TempProjectId = tempProjectId, error }));
        }
Ejemplo n.º 2
0
        private void _RemoveTempProject(int projectId)
        {
            _db = new ApplicationDbContext();

            var temoProject = (from u in _db.TempProjects
                               where u.TempProjectId == projectId
                               select u).FirstOrDefault();

            BlobConnector.RemoveIcon(projectId, false);
            _db.Entry(temoProject).State = System.Data.Entity.EntityState.Deleted;

            var tempProjectTechnologies = from u in _db.TempProjectTechnologies
                                          where u.ProjectId == projectId
                                          select u;

            foreach (var tpt in tempProjectTechnologies)
            {
                _db.Entry(tpt).State = System.Data.Entity.EntityState.Deleted;
            }

            var images = from u in _db.Images
                         where u.ProjectId == projectId && u.TempraryProject
                         select u;

            foreach (var img in images)
            {
                BlobConnector.RemoveImage(img);
                _db.Entry(img).State = System.Data.Entity.EntityState.Deleted;
            }

            _db.SaveChanges();
        }
Ejemplo n.º 3
0
        public ActionResult CreateProjectFromTempProject(int projectId)
        {
            _db = new ApplicationDbContext();

            var tempProject = (from x in _db.TempProjects
                               where x.TempProjectId == projectId
                               select x).FirstOrDefault();
            Project project = Mapper.Map <TempProject, Project>(tempProject);

            if (tempProject != null)
            {
                _db.Projects.Add(project);
            }
            _db.SaveChanges();

            BlobConnector.MoveIconFromTempToProject(projectId, project.ProjectId);

            ApplicationDbContext db2    = new ApplicationDbContext();
            var tempProjectTechnologies = from x in db2.TempProjectTechnologies
                                          where x.ProjectId == projectId
                                          select x;

            foreach (var tempProjectTechnology in tempProjectTechnologies)
            {
                ProjectTechnology projectTechnology = Mapper.Map <TempProjectTechnology, ProjectTechnology>(tempProjectTechnology);
                if (projectTechnology == null)
                {
                    continue;
                }
                projectTechnology.ProjectId = project.ProjectId;
                db2.ProjectTechnologies.Add(projectTechnology);
            }
            db2.SaveChanges();


            var imgList = from z in _db.Images
                          where z.ProjectId == projectId && z.TempraryProject
                          select z;

            foreach (var v in imgList)
            {
                BlobConnector.MoveImageFromTempToProject(v, project.ProjectId);
                v.FileName         = "Project" + project.ProjectId + v.OriginalFileName;
                v.TempraryProject  = false;
                v.ProjectId        = project.ProjectId;
                _db.Entry(v).State = System.Data.Entity.EntityState.Modified;
            }
            _db.SaveChanges();


            RemoveTempProject(projectId);

            return(RedirectToAction("ProjectsListView"));
        }
Ejemplo n.º 4
0
        public ActionResult RemoveIconFromProject(int projectId)
        {
            _db = new ApplicationDbContext();
            var project = (from u in _db.Projects where u.ProjectId == projectId select u).First();

            BlobConnector.RemoveIcon(projectId, true);
            project.IsIcon           = false;
            _db.Entry(project).State = System.Data.Entity.EntityState.Modified;
            _db.SaveChanges();

            return(RedirectToAction("EditProjectView", new { projectId }));
        }
Ejemplo n.º 5
0
        public ActionResult UploadProjImage(HttpPostedFileBase file, int projectId)
        {
            _db = new ApplicationDbContext();

            Image image = new Image()
            {
                OriginalFileName = file.FileName,
                FileName         = "Project" + projectId + file.FileName,
                ProjectId        = projectId,
                TempraryProject  = false
            };

            BlobConnector.UploadImage(file, image);
            _db.Images.Add(image);
            _db.SaveChanges();

            return(RedirectToAction("EditProjectView", new { projectId }));
        }
Ejemplo n.º 6
0
        public ActionResult UploadTempProjImage(HttpPostedFileBase file, int tempProjectId)
        {
            _db = new ApplicationDbContext();

            Image image = new Image()
            {
                OriginalFileName = file.FileName,
                FileName         = "TempProject" + tempProjectId + file.FileName,
                ProjectId        = tempProjectId,
                TempraryProject  = true
            };

            BlobConnector.UploadImage(file, image);
            _db.Images.Add(image);
            _db.SaveChanges();

            return(RedirectToAction("CreateTempProjectView2", new { TempProjectId = tempProjectId }));
        }
Ejemplo n.º 7
0
        public ActionResult RemoveImageFromProject(int imageId, int projectId)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            var image = (from u in db.Images
                         where u.ImageId == imageId
                         select u).FirstOrDefault();

            if (image == null)
            {
                return(RedirectToAction("EditProjectView", new { projectId }));
            }
            BlobConnector.RemoveImage(image);
            db.Images.Remove(image);
            db.SaveChanges();

            return(RedirectToAction("EditProjectView", new { projectId }));
        }
Ejemplo n.º 8
0
        public ActionResult RemoveProject(int projectId)
        {
            _db = new ApplicationDbContext();

            var project = (from u in _db.Projects
                           where u.ProjectId == projectId
                           select u).FirstOrDefault();

            BlobConnector.RemoveIcon(projectId, true);

            _db.Entry(project).State = System.Data.Entity.EntityState.Deleted;

            var projectTechnologies = from u in _db.ProjectTechnologies
                                      where u.ProjectId == projectId
                                      select u;

            foreach (var tpt in projectTechnologies)
            {
                _db.Entry(tpt).State = System.Data.Entity.EntityState.Deleted;
            }

            var images = from u in _db.Images
                         where u.ProjectId == projectId && u.TempraryProject == false
                         select u;

            foreach (var img in images)
            {
                BlobConnector.RemoveImage(img);
                _db.Entry(img).State = System.Data.Entity.EntityState.Deleted;
            }

            _db.SaveChanges();


            return(RedirectToAction("ProjectsListView"));
        }