Beispiel #1
0
        public ActionResult Edit(string id, Project project, string ManagerId, HttpPostedFileBase upload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var oldProject = _unitOfWork.ProjectRepositry.SingleOrDefault(p => p.Id == id);
                    oldProject.Name        = project.Name;
                    oldProject.StartTime   = project.StartTime;
                    oldProject.DeadTime    = project.DeadTime;
                    oldProject.Description = project.Description;



                    //update manager in that table
                    var newProjectManager = new ProjectManagerTable()
                    {
                        ProjectID = id,
                        ManagerID = ManagerId
                    };

                    //Guid is used as a file name on the basis that it can pretty much guarantee uniqueness
                    if (upload != null && upload.ContentLength > 0)
                    {
                        var photo = new MyProjectFile()
                        {
                            FileName   = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(upload.FileName),
                            MyFileType = MyFileType.Photo
                        };


                        string physicalPath = Server.MapPath("~/images/" + photo.FileName);

                        // save image in folder
                        upload.SaveAs(physicalPath);
                        oldProject.ProjectFiles = new List <MyProjectFile>();


                        oldProject.ProjectFiles.Add(photo);
                    }
                    _unitOfWork.ProjectMangerRepositry.Add(newProjectManager);//this is for add or update

                    _unitOfWork.Complete();
                }

                if (User.IsInRole("Admin"))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("ShowProjectsForManager"));
                }
            }
            catch (Exception exception)
            {
                return(View());
            }
        }
Beispiel #2
0
        protected override void Seed(ApplicationDbContext context)
        {
            //Add Test User
            InitUsers(context);
            context.SaveChanges();

            //Add Clients
            var clientList = new List <Client>
            {
                new Client()
                {
                    Name                = "Client 1",
                    Email               = "*****@*****.**",
                    Address             = "Alnasser Street",
                    AdditionInformation = "I want many things",
                },
                new Client()
                {
                    Name                = "Client 2",
                    Email               = "*****@*****.**",
                    Address             = "Alnasser Street",
                    AdditionInformation = "I want many things2",
                },
                new Client()
                {
                    Name                = "Client 3",
                    Email               = "*****@*****.**",
                    Address             = "Alnasser Street",
                    AdditionInformation = "I want many things3",
                }
            };

            clientList.ForEach(c => context.Clients.AddOrUpdate(client => client.Id, c));
            context.SaveChanges();

            //Add projects
            var projects = new List <Project>
            {
                new Project()
                {
                    Id           = "Project0",
                    Name         = "WallPaper App ",
                    StartTime    = DateTime.Now,
                    DeadTime     = DateTime.Now.AddDays(20),
                    Status       = StatusEnum.Not_Start,
                    Description  = "Description 0",
                    ClientId     = clientList[0].Id,
                    Users        = _users,
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project1",
                    Name        = "Family App ",
                    StartTime   = DateTime.Now,
                    DeadTime    = DateTime.Now.AddDays(60),
                    Status      = StatusEnum.InProgress,
                    Description = "Description 1",

                    ClientId     = clientList[0].Id,
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project2",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 2",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    ClientId     = clientList[2].Id,
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project3",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 3",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    ClientId     = clientList[2].Id,
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project4",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 4",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    ClientId     = clientList[2].Id,
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project5",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 5",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    ClientId     = clientList[2].Id,
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project6",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 6",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    ClientId     = clientList[2].Id,
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project7",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description7",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[2],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project8",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 8",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[2],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project9",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description9",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[0],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project10",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 10",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[0],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project11",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 11",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[0],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project12",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 12",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[1],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project13",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 13",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[1],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project 14",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 14",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[1],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project15",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 15",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[1],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project16",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 16",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[1],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project17",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 2",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[1],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                },
                new Project()
                {
                    Id          = "Project18",
                    Name        = "Movies ",
                    StartTime   = DateTime.Now,
                    Description = "Description 2",

                    DeadTime     = DateTime.Now.AddDays(555),
                    Status       = StatusEnum.Not_Start,
                    Client       = clientList[1],
                    ProjectFiles = new List <MyProjectFile>
                    {
                        new MyProjectFile()
                        {
                            FileName   = "~/images/ccad8040-b454-4fa0-8c51-d66984dda0dd.png",
                            MyFileType = MyFileType.Photo
                        }
                    }
                }
            };

            projects.ForEach(p => context.Projects.AddOrUpdate(project => project.Id, p));
            context.SaveChanges();



            //add manager for each project
            foreach (var project in projects)
            {
                var pm = new ProjectManagerTable()
                {
                    //one manager for all project to test only !!
                    ManagerID = _users[0].Id,
                    ProjectID = project.Id
                };
                context.ProjectManagerTable.Add(pm);
            }
        }
Beispiel #3
0
        public ActionResult Create(CreateProjectViewModels viewmodel, string __UserId__, int status, HttpPostedFileBase upload)
        {
            try
            {
                if (viewmodel == null)
                {
                    return(HttpNotFound());
                }

                //if (!ModelState.IsValid)
                //{
                //    var errors = ModelState.Values.SelectMany(vr => vr.Errors);
                //    var s = ModelState.Values;
                //    var v = new IndexViewModels()
                //    {
                //        Project = new Project(),
                //        Users = _unitOfWork.UserRepositry.GetAll().ToList(),
                //        Clients = _unitOfWork.ClientRepositry.GetAll().ToList()

                //    };

                //    return View(v);
                //}

                //Add To Projects..we need user,client,to add them to project



                //get client
                //Note , here i send Name of client but i name ClientId in that form

                //var client = _unitOfWork.ClientRepositry.SingleOrDefault(c => c.Name == ClientId);



                //only corspond data will be set ,so users,clinet will be null
                var newProject = new Project()
                {
                    Id           = viewmodel.Project.Id,
                    Name         = viewmodel.Project.Name,
                    DeadTime     = viewmodel.Project.DeadTime,
                    StartTime    = viewmodel.Project.StartTime,
                    Status       = (StatusEnum)Enum.ToObject(typeof(StatusEnum), status),
                    Description  = viewmodel.Project.Description,
                    ClientId     = 1,
                    Users        = new List <ApplicationUser>(),//this is must
                    ProjectFiles = new List <MyProjectFile>()
                };

                //get user manager
                if (!__UserId__.IsEmpty())
                {
                    var userManager = _unitOfWork.UserRepositry.SingleOrDefault(u => u.Id == __UserId__);
                    //Add this manger
                    //newProject.Users.Add(user);
                    var pm = new ProjectManagerTable()
                    {
                        ManagerID = userManager.Id,
                        ProjectID = viewmodel.Project.Id
                    };

                    _unitOfWork.ProjectMangerRepositry.Add(pm);
                }

                //Guid is used as a file name on the basis that it can pretty much guarantee uniqueness
                if (upload != null && upload.ContentLength > 0)
                {
                    var photo = new MyProjectFile()
                    {
                        FileName   = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(upload.FileName),
                        MyFileType = MyFileType.Photo
                    };


                    string physicalPath = Server.MapPath("~/images/" + photo.FileName);

                    // save image in folder
                    upload.SaveAs(physicalPath);
                    newProject.ProjectFiles.Add(photo);
                }


                _unitOfWork.ProjectRepositry.Add(newProject);

                _unitOfWork.Complete();


                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }