예제 #1
0
        public static int AddWork(Data toDo)
        {
            // transaction à ajouter stp
            int      toDoId;
            DateTime?toDoStart;
            DateTime?toDoEnd;

            toDoId = toDo.Id;
            bool NoExternalNote = toDo.NoExternalNote;

            if (toDo.Id == -1)
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    try
                    {
                        var aJob = new toDo
                        {
                            Description = toDo.Description,
                            Begin       = toDo.Begin,
                            End         = toDo.End,
                            Duration    = toDo.Duration,
                            Reference   = toDo.Reference,
                            Done        = false,
                            Planned     = toDo.Planned,
                            Notes       = "",
                            Branch      = toDo.Branch,
                            Status      = toDo.Appraisal,
                            Status_Note = toDo.AppraisalNote
                        };
                        if (NoExternalNote)
                        {
                            aJob.Notes = toDo.Notes;
                        }
                        dbContext.toDos.Add(aJob);
                        dbContext.SaveChanges();

                        toDoId    = aJob.Id;
                        toDoStart = aJob.Begin;
                        toDoEnd   = aJob.End;
                        var aTimeChunk = new Break
                        {
                            Start  = toDoStart,
                            End    = toDoEnd,
                            ToDoId = toDoId
                        };

                        dbContext.Breaks.Add(aTimeChunk);
                        dbContext.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        // throw new Exception(String.Format("the error is : {0}", e));
                    }
                }
            }
            else
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    toDo job = dbContext.toDos.Find(toDo.Id);

                    if (job == null)
                    {
                        throw new Exception("Echec mise a jour");
                    }

                    job.Description = toDo.Description;
                    job.Begin       = toDo.Begin;
                    job.End         = toDo.End;
                    job.Duration    = toDo.Duration;
                    job.Reference   = toDo.Reference;
                    job.Done        = toDo.Done;
                    job.Notes       = "";
                    if (NoExternalNote)
                    {
                        job.Notes = toDo.Notes;
                    }
                    job.Planned     = toDo.Planned;
                    job.Branch      = toDo.Branch;
                    job.Status      = toDo.Appraisal;
                    job.Status_Note = toDo.AppraisalNote;
                    dbContext.SaveChanges();
                }
            }

            if (toDo.Notes != "" && (!NoExternalNote))
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    var aNote = new Note
                    {
                        Subject   = "",
                        Body      = toDo.Notes,
                        Concern   = "work",
                        Creation  = DateTime.Now,
                        ConcernId = toDoId
                    };
                    dbContext.Notes.Add(aNote);
                    dbContext.SaveChanges();
                }
            }
            return(toDoId);
        }
예제 #2
0
        public static int AddPeople(DataToAddPeople People)
        {
            int Id = People.Id;

            if (People.Position == -1 && People.PositionName != "")
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    Position role = dbContext.Positions.FirstOrDefault(x => x.Name == People.PositionName);

                    if (role == null)
                    {
                        role = new Position
                        {
                            Name = People.PositionName.ToUpper(),
                        };
                        dbContext.Positions.Add(role);
                        dbContext.SaveChanges();
                        People.Position = role.Id;
                    }
                    else
                    {
                        People.Position = role.Id;
                    }
                }
            }
            if (Id == -1)
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    var aPerson = new Person
                    {
                        Nom        = People.Nom,
                        Prenom     = People.Prenom,
                        IdPosition = People.Position,
                        Mobile     = People.Mobile,
                        Email      = People.Email,
                        Photo      = ""
                    };
                    dbContext.People.Add(aPerson);
                    dbContext.SaveChanges();
                    Id = aPerson.Id;
                }
            }
            else
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    Person aPerson = dbContext.People.Find(Id);

                    if (aPerson == null)
                    {
                        throw new Exception("Echec mise a jour");
                    }

                    aPerson.Nom        = People.Nom;
                    aPerson.Prenom     = People.Prenom;
                    aPerson.IdPosition = People.Position;
                    aPerson.Mobile     = People.Mobile;
                    aPerson.Email      = People.Email;

                    dbContext.SaveChanges();
                }
            }
            //
            if (People.NewNote != "")
            {
                //   Notes = query3.Where(z => z.ConcernId == x.Id && z.Concern == "people").ToList()
                using (var dbContext = new QuickToDosEntities())
                {
                    var aNote = new Note
                    {
                        Subject   = "",
                        Body      = People.NewNote,
                        Concern   = "people",
                        Creation  = DateTime.Now,
                        ConcernId = Id
                    };
                    dbContext.Notes.Add(aNote);
                    dbContext.SaveChanges();
                }
            }
            return(Id);
        }