public ProjectRoleType Update(ProjectRoleType projectRoleType)
        {
            ProjectRoleType projectRoleTypeTest = context.ProjectRoleType.Find(projectRoleType.RoleId);

            projectRoleTypeTest.RoleName = projectRoleType.RoleName;

            context.Entry(projectRoleTypeTest).State = EntityState.Modified;
            context.SaveChanges();

            return(projectRoleTypeTest);
            //projectRoleTypeRepository.Update(projectRoleType);
        }
        public void Remove(int id)
        {
            ProjectRoleType entityToDelete   = context.ProjectRoleType.Find(id);
            List <Activity> activityToDelete = new List <Activity>();
            var             zmienna          = context.Activity.Where(i => i.CurrentProjectRoleType.RoleId == entityToDelete.RoleId);

            foreach (var item in zmienna)
            {
                context.Activity.Remove(item);
            }
            context.ProjectRoleType.Remove(entityToDelete);
            context.SaveChanges();
        }
 public IHttpActionResult PutProjectRoleType(ProjectRoleType publicRoleType)
 {
     //var publicRoleTypeDb = projectRoleTypeService.Get(publicRoleType.RoleId);
     if (publicRoleType != null)
     {
         var returnData = projectRoleTypeService.Update(publicRoleType);
         return(Ok(returnData));
     }
     else
     {
         return(NotFound());
     }
 }
        public Activity Update(Activity dailyActivity)
        {
            Activity        activityToEdit     = context.Activity.Find(dailyActivity.Id);
            Project         projectToEdit      = context.Project.Find(dailyActivity.Project.ProjectId);
            ActivityType    activityTypeToEdit = context.ActivityType.Find(dailyActivity.ActivityType.ActivityId);
            ProjectRoleType projectRoleToEdit  = context.ProjectRoleType.Find(dailyActivity.CurrentProjectRoleType.RoleId);

            activityToEdit.Begining               = dailyActivity.Begining;
            activityToEdit.HowManyHours           = dailyActivity.HowManyHours;
            activityToEdit.description            = dailyActivity.description;
            activityToEdit.ActivityType           = activityTypeToEdit;
            activityToEdit.Project                = projectToEdit;
            activityToEdit.CurrentProjectRoleType = projectRoleToEdit;
            activityToEdit.ApprovedByManager      = dailyActivity.ApprovedByManager;

            context.Entry(activityToEdit).State = EntityState.Modified;
            context.SaveChanges();
            return(activityToEdit);
        }
 public ProjectRoleType Add(ProjectRoleType projectRoleType)
 {
     return(projectRoleTypeRepository.Add(projectRoleType));
 }
示例#6
0
        protected override void Seed(TimesheetDbContext context)
        {
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            if (!roleManager.RoleExists(Startup.roleAdmin))
            {
                roleManager.Create(new IdentityRole(Startup.roleAdmin));
            }

            if (!roleManager.RoleExists(Startup.roleUser))
            {
                roleManager.Create(new IdentityRole(Startup.roleUser));
            }

            if (!roleManager.RoleExists(Startup.roleManager))
            {
                roleManager.Create(new IdentityRole(Startup.roleManager));
            }


            var userKrzysztof = userManager.FindByEmail("*****@*****.**");

            if (userKrzysztof == null)
            {
                userKrzysztof = new ApplicationUser
                {
                    Email     = "*****@*****.**",
                    UserName  = "******",
                    FirstName = "Krzysztof",
                    LastName  = "Kluszczynski",
                };
                string passwordKrzysztof = "Password1!";
                userManager.Create(userKrzysztof, passwordKrzysztof);
                userManager.AddToRole(userKrzysztof.Id, Startup.roleAdmin);
            }

            var userPiotr = userManager.FindByEmail("*****@*****.**");

            if (userPiotr == null)
            {
                userPiotr = new ApplicationUser
                {
                    Email      = "*****@*****.**",
                    UserName   = "******",
                    FirstName  = "Piotr",
                    LastName   = "Nasiñski",
                    SuperiorId = userKrzysztof.Id
                };
                string passwordPiotr = "Password1!";
                userManager.Create(userPiotr, passwordPiotr);
                userManager.AddToRole(userPiotr.Id, Startup.roleManager);
            }

            var userJakub = userManager.FindByEmail("*****@*****.**");

            if (userJakub == null)
            {
                userJakub = new ApplicationUser
                {
                    Email      = "*****@*****.**",
                    UserName   = "******",
                    FirstName  = "Jakub",
                    LastName   = "Wycinka",
                    SuperiorId = userPiotr.Id
                };
                string passwordJakub = "Password1!";
                userManager.Create(userJakub, passwordJakub);
                userManager.AddToRole(userJakub.Id, Startup.roleUser);
            }

            var userSlawomir = userManager.FindByEmail("*****@*****.**");

            if (userSlawomir == null)
            {
                userSlawomir = new ApplicationUser
                {
                    Email      = "*****@*****.**",
                    UserName   = "******",
                    FirstName  = "S³awomir",
                    LastName   = "Rzeppa",
                    SuperiorId = userPiotr.Id
                };
                string passwordSlawomir = "Password1!";
                userManager.Create(userSlawomir, passwordSlawomir);
                userManager.AddToRole(userSlawomir.Id, Startup.roleUser);
            }


            ProjectType projectBillable = new ProjectType {
                Name = "Billable"
            };
            ProjectType projectNonBillable = new ProjectType {
                Name = "Non-Billable"
            };

            Project project1 = new Project {
                Name = "Timesheet", ProjectType = projectNonBillable, Client = "XXX", Projectnumber = "B21"
            };
            Project project2 = new Project {
                Name = "Artifex", ProjectType = projectBillable, Client = "VVV", Projectnumber = "B22"
            };
            Project project3 = new Project {
                Name = "DD-PACK", ProjectType = projectBillable, Client = "YYY", Projectnumber = "C32"
            };
            Project project4 = new Project {
                Name = "IMPAQ", ProjectType = projectBillable, Client = "XXX", Projectnumber = "D21"
            };


            ActivityType activityType1 = new ActivityType {
                Name = "Working"
            };
            ActivityType activityType2 = new ActivityType {
                Name = "Sickness"
            };
            ActivityType activityType3 = new ActivityType {
                Name = "Holidays"
            };
            ActivityType activityType4 = new ActivityType {
                Name = "Bank Holidays"
            };
            ActivityType activityType5 = new ActivityType {
                Name = "Event"
            };
            ActivityType activityType6 = new ActivityType {
                Name = "Other"
            };

            ProjectRoleType projectRoleType1 = new ProjectRoleType {
                RoleName = "Back-End Developer"
            };
            ProjectRoleType projectRoleType2 = new ProjectRoleType {
                RoleName = "Front-end Developer"
            };
            ProjectRoleType projectRoleType3 = new ProjectRoleType {
                RoleName = "Team leader"
            };
            ProjectRoleType projectRoleType4 = new ProjectRoleType {
                RoleName = "Other"
            };

            Activity activity1 = new Activity
            {
                Begining = DateTime.Now,
                Project  = project1,
                CurrentProjectRoleType = projectRoleType2,
                ActivityType           = activityType1,
                UserId       = userJakub.Id,
                HowManyHours = 8,
            };
            Activity activity2 = new Activity
            {
                Begining = DateTime.Now.AddDays(-1),
                //  End = DateTime.Now.AddDays(-1).AddHours(8),
                Project = project1,
                CurrentProjectRoleType = projectRoleType2,
                ActivityType           = activityType1,
                UserId       = userJakub.Id,
                HowManyHours = 8,
            };
            Activity activity3 = new Activity
            {
                Begining = DateTime.Now.AddDays(-2),
                // End = DateTime.Now.AddDays(-2).AddHours(8),
                Project = project1,
                CurrentProjectRoleType = projectRoleType1,
                ActivityType           = activityType1,
                UserId       = userJakub.Id,
                HowManyHours = 7,
            };
            Activity activity4 = new Activity
            {
                Begining = DateTime.Now.AddDays(-3),
                //End = DateTime.Now.AddDays(-3).AddHours(8),
                CurrentProjectRoleType = projectRoleType4,
                Project      = project1,
                ActivityType = activityType1,
                UserId       = userJakub.Id,
                HowManyHours = 8,
            };

            context.ProjectType.AddOrUpdate(x => x.Name, projectBillable, projectNonBillable);
            context.Project.AddOrUpdate(x => x.Name, project1, project2, project3, project4);
            context.ActivityType.AddOrUpdate(x => x.Name, activityType1, activityType2,
                                             activityType3, activityType4, activityType5, activityType6);
            context.ProjectRoleType.AddOrUpdate(x => x.RoleName, projectRoleType1, projectRoleType2,
                                                projectRoleType3, projectRoleType4);
            context.Activity.AddOrUpdate(x => x.Id, activity1, activity2, activity3, activity4);
            // context.Users.AddOrUpdate(x => x.Id, userJakub, userKrzysztof, userPiotr, userSlawomir);
            context.SaveChanges();
        }
        public IHttpActionResult PostProjectRoleType(ProjectRoleType projectRoleType)
        {
            var returnData = projectRoleTypeService.Add(projectRoleType);

            return(Ok(returnData));
        }