Ejemplo n.º 1
0
 public void AddProject(Project project)
 {
     var l = project.FinishedSteps.ToList();
     using (var ctx = new StepMapDbContext())
     {
         project = ctx.Projects.Add(project);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public void DALTest2()
        {
            using (StepMapDbContext ctx = new StepMapDbContext())
            {
                User u = new User();
                u.Email = "*****@*****.**";
                u.LastLogin = DateTime.UtcNow;
                u.Name = "test user";
                u.PasswordHash = "hash";
                u.UserRole = UserRole.Member;
                u.UserState = UserState.Active;

                Project p = new Project();
                p.Name = "test project";
                p.User = u;

                Step s = new Step();
                s.Name = "test step name";
                s.Project = p;

                Reminder r = new Reminder();
                r.Step = s;
                r.EmailAddress = "*****@*****.**";
                r.Message = "test message";
                r.SentDate = DateTime.UtcNow;
                r.Subject = "test subject";

                ctx.Projects.Add(p);
                ctx.Steps.Add(s);
                ctx.Reminders.Add(r);

                ctx.SaveChanges();

                try
                {
                    Project dp = ctx.Projects.Single(tu => tu.Name == "test project");
                    Assert.AreEqual(p.UserId, dp.UserId);
                    Step ds = dp.FinishedSteps.Single();
                    Assert.AreEqual(s.Name, ds.Name);
                    Reminder dr = ds.SentReminders.Single();
                    Assert.AreEqual(dr.EmailAddress, r.EmailAddress);
                    Assert.AreEqual(dr.Message, r.Message);
                    Assert.AreEqual(dr.SentDate, r.SentDate);
                    Assert.AreEqual(dr.Subject, r.Subject);
                }
                finally
                {
                    s.SentReminders.Clear();
                    p.FinishedSteps.Clear();
                    ctx.Reminders.Remove(r);
                    ctx.Steps.Remove(s);
                    ctx.Projects.Remove(p);
                    ctx.Users.Remove(u);
                    ctx.SaveChanges();
                }
            }
        }
Ejemplo n.º 3
0
        public static dal.Project ConvertProject(dto.Project project)
        {
            dal.Project ret = new dal.Project();
            ret.Id = project.Id;
            ret.UserId = project.UserId;
            ret.BadPoint = project.BadPoint;
            ret.GoodPoint = project.GoodPoint;
            ret.Name = project.Name;
            ret.StartDate = project.StartDate;
            ret.Position = project.Position;

            ret.FinishedSteps = project.FinishedSteps.Select(s => StepConverter.ConvertStep(s)).ToList();
            return ret;
        }
Ejemplo n.º 4
0
 public void UpdateProject(Project project)
 {
     using (var ctx = new StepMapDbContext())
     {
         project = ctx.Projects.Attach(project);
         
         ctx.Entry(project).State = EntityState.Modified;
         foreach(var step in ctx.Steps.Where(s=>s.Id != 0))
         {
             var s = ctx.Steps.Attach(step);
             ctx.Entry(s).State = EntityState.Modified;
         }
         ctx.Steps.AddRange(project.FinishedSteps.Where(s => s.Id == 0));
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 private void SentFirstReminder(User user, Project project, Step step)
 {
     using (var ctx = new StepMapDbContext())
     {
         //TODO: Config, customize, randomize
         Reminder reminder = new Reminder()
         {
             EmailAddress = user.Email,
             Message = string.Format("Your current step ({0}) in project {1} is delayed! Get yourself together!", step.Name, project.Name), //LOCSTR
             Subject = "First reminder", //LOCSTR
             SentDate = DateTime.UtcNow,
             StepId = step.Id
         };
         ctx.Reminders.Add(reminder);
         notificationManager.SendEmail(user, reminder.Subject, reminder.Message);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 6
0
        public void CheckProjectProgress(Project project)
        {
            using (var ctx = new StepMapDbContext())
            {
                Step currentStep = project.FinishedSteps.Last();
                if (currentStep.Deadline < DateTime.UtcNow)
                {
                    project.BadPoint++;
                    if (!currentStep.SentReminders.Any())
                    {
                        SentFirstReminder(project.User, project, currentStep);
                        ctx.Projects.Attach(project);
                    }
                }

                ctx.SaveChanges();
            }
        }