Ejemplo n.º 1
0
        public static void DeleteWork(InfoId toDel)
        {
            using (var dbContext = new QuickToDosEntities())
            {
                bool         go      = true;
                List <Break> results = dbContext.Breaks.Where(x => x.ToDoId == toDel.Id).ToList();
                if (results != null)
                {
                    foreach (Break result in results)
                    {
                        dbContext.Breaks.Remove(result);
                    }
                }

                toDo job = dbContext.toDos.Find(toDel.Id);
                if (job == null)
                {
                    go = false;
                }
                if (go)
                {
                    try
                    {
                        job.DontShow = true;

                        //dbContext.toDos.Remove(job);
                        dbContext.SaveChanges();
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void DeleteImg(InfoId toDel)
        {
            using (var dbContext = new QuickToDosEntities())
            {
                File anImage = dbContext.Files.Find(toDel.Id);
                if (anImage != null)
                {
                    string   filename = anImage.Filename;
                    string[] items    = filename.Split('/');
                    filename = items[items.Length - 1];

                    string concern          = anImage.Concern;
                    string uploadPath       = ConfigurationManager.AppSettings["RootFolder"] + @"\documents\" + concern + @"\";
                    string UploadPathOldies = uploadPath + @"oldies\";

                    string sourceFile = System.IO.Path.Combine(uploadPath, filename);
                    string destFile   = System.IO.Path.Combine(UploadPathOldies, filename);

                    if (!System.IO.Directory.Exists(UploadPathOldies))
                    {
                        System.IO.Directory.CreateDirectory(UploadPathOldies);
                    }
                    System.IO.File.Move(sourceFile, destFile);

                    dbContext.Files.Remove(anImage);
                    dbContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 3
0
        public static PauseInfo DoTogglePause(int jobId)
        {
            PauseInfo pauseInfo = new PauseInfo();

            pauseInfo.Duration = 0;
            pauseInfo.Paused   = false;

            using (var dbContext = new QuickToDosEntities())
            {
                List <Break> timeChunks = dbContext.Breaks.Where(x => x.ToDoId == jobId).ToList();
                if (timeChunks != null)
                {
                    timeChunks = timeChunks.OrderByDescending(x => x.Id).ToList();
                    if (timeChunks[0].End == null)
                    {
                        int   Id    = timeChunks[0].Id;
                        Break chunk = dbContext.Breaks.Find(Id);
                        if (chunk != null)
                        {
                            chunk.End = DateTime.Now;

                            dbContext.SaveChanges();
                            pauseInfo.Paused = true;
                        }
                    }
                    else
                    {
                        var chunk = new Break
                        {
                            Start  = DateTime.Now,
                            ToDoId = jobId
                        };

                        dbContext.Breaks.Add(chunk);
                        dbContext.SaveChanges();
                    }
                }
            }
            pauseInfo.Duration = CalcMinutes(jobId);

            return(pauseInfo);
        }
Ejemplo n.º 4
0
        public static string getForecast()
        {
            //6942553	Paris	43.200001	-80.383331	CA
            //3038354	Aix-en-Provence	43.528301	5.449730	FR
            //6444007	Maisons-Laffitte	48.950001	2.15	FR

            string output;
            string data     = "";
            string paris_id = "6942553";
            string key      = "0b2c2c31d711fe4ae9048808d3722eeb";
            string sURL     = "http://api.openweathermap.org/data/2.5/forecast?id=" + paris_id + "&APPID=" + key + "&units=metric";

            DateTime someTimeAgo = System.DateTime.Now.AddHours(-2);;

            using (var dbContext = new QuickToDosEntities())
            {
                List <API> results = dbContext.APIs.Where(x => x.creation > someTimeAgo).ToList();
                if (results != null)
                {
                    data = results[0].content;
                }
                else
                {
                    WebRequest   wrGETURL  = WebRequest.Create(sURL);
                    Stream       objStream = wrGETURL.GetResponse().GetResponseStream();
                    StreamReader objReader = new StreamReader(objStream);
                    string       sLine     = "";
                    int          i         = 0;

                    while (sLine != null)
                    {
                        i++;
                        output = objReader.ReadLine();
                        if (sLine != null)
                        {
                            output += sLine + Environment.NewLine;
                        }
                    }
                    var anApi = new API
                    {
                        concern  = "weather",
                        content  = sLine,
                        creation = DateTime.Now
                    };
                    data = sLine;
                    dbContext.APIs.Add(anApi);
                    dbContext.SaveChanges();
                }
            }

            return(data);
        }
Ejemplo n.º 5
0
 public static void DeleteKnowledge(InfoId toDel)
 {
     using (var dbContext = new QuickToDosEntities())
     {
         Knowledge aKnowledge = dbContext.Knowledges.Find(toDel.Id);
         if (aKnowledge == null)
         {
             throw new Exception("Echec mise a jour");
         }
         dbContext.Knowledges.Remove(aKnowledge);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 6
0
        public static int ToggleDone(InfoDone info)
        {
            if (info == null)
            {
                throw new Exception("Echec mise a jour (1)");
            }
            PauseInfo pauseInfo = new PauseInfo();
            int       nrMinutes = 0;
            var       jobId     = info.Id;

            using (var dbContext = new QuickToDosEntities())
            {
                toDo job = dbContext.toDos.Find(jobId);

                if (job == null)
                {
                    throw new Exception("Echec mise a jour (2)");
                }
                if ((bool)info.Done) // We close
                {
                    job.End = DateTime.Now;

                    if (job.Begin == null)
                    {
                        job.Begin = job.End;
                    }
                    else
                    {
                        pauseInfo = DoTogglePause(jobId);
                        nrMinutes = pauseInfo.Duration;
                        if (!pauseInfo.Paused)
                        {
                            pauseInfo = DoTogglePause(jobId);
                            nrMinutes = pauseInfo.Duration;
                        }
                    }
                }
                else // We open again
                {
                    job.End = null;
                }

                job.Done     = info.Done;
                job.Duration = nrMinutes;
                dbContext.SaveChanges();
            }

            return(nrMinutes);
        }
Ejemplo n.º 7
0
        public static int AddKnowledge(KnowAdd Know)
        {
            if (Know.Id == -1)
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    var aKnowledge = new Knowledge
                    {
                        Subject  = Know.Subject,
                        Body     = Know.Body,
                        Creation = DateTime.Now
                    };
                    dbContext.Knowledges.Add(aKnowledge);
                    dbContext.SaveChanges();
                    Know.Id = aKnowledge.Id;
                }
            }
            else
            {
                using (var dbContext = new QuickToDosEntities())
                {
                    Knowledge aKnowledge = dbContext.Knowledges.Find(Know.Id);

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

                    aKnowledge.Subject      = Know.Subject;
                    aKnowledge.Body         = Know.Body;
                    aKnowledge.Modification = DateTime.Now;
                    dbContext.SaveChanges();
                }
            }
            return(Know.Id);
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            System.Diagnostics.Debugger.Launch();

            try
            {
                if (context.Request.Files.Count > 0)
                {
                    HttpPostedFile file     = context.Request.Files[0];
                    string         fileName = file.FileName;

                    if (!string.IsNullOrEmpty(fileName))
                    {
                        string Idstr       = context.Request.Params["Id"];
                        int    Id          = int.Parse(Idstr);
                        string Concern     = context.Request.Params["Concern"];
                        string Description = context.Request.Params["Description"];
                        if (Description == null)
                        {
                            Description = "";
                        }
                        int fileId = 0;

                        //  string data64 = context.Request.Params["File"];

                        using (var dbContext = new QuickToDosEntities())
                        {
                            var aFile = new File
                            {
                                Filename    = "temp",
                                Concern     = Concern,
                                ExtId       = Id,
                                Description = Description
                            };
                            dbContext.Files.Add(aFile);
                            dbContext.SaveChanges();
                            fileId = aFile.Id;
                            if (Concern == "people")
                            {
                                if (fileName == "blob")
                                {
                                    string type = context.Request.Params["Type"];
                                    if (type == "jpeg")
                                    {
                                        fileName = "image.jpg";
                                    }
                                    else
                                    {
                                        fileName = "image." + type;
                                    }
                                }
                                aFile.Filename = string.Format("/images/{0}_{1}_{2}", Idstr, fileId, fileName);
                                dbContext.SaveChanges();

                                Person aPerson = dbContext.People.Find(Id);

                                if (aPerson != null)
                                {
                                    aPerson.Photo = aFile.Filename;
                                    dbContext.SaveChanges();
                                }
                            }
                            else
                            {
                                aFile.Filename = string.Format("/documents/{0}/{1}_{2}_{3}", Concern, Idstr, fileId, fileName);
                                dbContext.SaveChanges();
                            }
                        }
                        string documentsPath = "";
                        if (Concern == "people")
                        {
                            documentsPath = context.Server.MapPath("") + @"\images\";
                        }
                        else
                        {
                            documentsPath = context.Server.MapPath("") + @"\documents\" + Concern + "\\";
                        }

                        System.IO.Directory.CreateDirectory(documentsPath);
                        string fileToSave = documentsPath + string.Format("{0}_{1}_{2}", Idstr, fileId, fileName);


                        file.SaveAs(fileToSave);
                        if (Concern == "people")
                        {
                            const int maxHeight      = 450;
                            Image     original       = Image.FromFile(fileToSave);
                            int       originalWidth  = original.Width;
                            int       originalHeight = original.Height;
                            if (originalHeight > maxHeight)
                            {
                                double factor;
                                factor = (double)maxHeight / originalHeight;
                                int   newHeight = maxHeight;
                                int   newWidth  = (int)(originalWidth * factor);
                                Image thumbnail = original.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
                                original.Dispose();
                                thumbnail.Save(fileToSave);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }