public static KnowHow GetKnowledge() { KnowHow knowledge = new KnowHow() { caption = "Base de connaissances", headers = new string[] { "Id", "Subject", "Creation", "Modification" }, types = new string[] { "number", "string", "datetime", "datetime" }, props = new string[] { "Id", "Subject", "Creation", "Modification" } }; using (var dbContext = new QuickToDosEntities()) { IQueryable <Knowledge> query = dbContext.Knowledges; knowledge.data = query.Select(x => new DataForKnowledge { Id = x.Id, Subject = x.Subject, Creation = x.Creation, Modification = x.Modification, Body = x.Body }).ToList(); } knowledge.data = knowledge.data.OrderByDescending(x => x.Id).Take(100).ToList(); foreach (DataForKnowledge know in knowledge.data) { know.Files = getFiles(know.Id, "knowledge"); } return(knowledge); }
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) { } } } }
public static PeopleObject GetPeople() { PeopleObject card = new PeopleObject() { caption = "Personnages", headers = new string[] { "Id", "Nom", "Prénom", "Position", "Mobile", "Email" }, types = new string[] { "number", "string", "string", "string", "string" }, props = new string[] { "Id", "Nom", "Prenom", "Position", "Mobile", "Email" } }; using (var dbContext = new QuickToDosEntities()) { IQueryable <Person> query = dbContext.People; IQueryable <Position> query2 = dbContext.Positions; IQueryable <Note> query3 = dbContext.Notes; card.data = query.Select(x => new DataForPeople { Id = x.Id, Nom = x.Nom, Prenom = x.Prenom, IdPosition = x.IdPosition != null ? (int)x.IdPosition : 0, Email = x.Email, Mobile = x.Mobile, Photo = x.Photo != null ? x.Photo:"", Position = query2.Where(y => y.Id == x.IdPosition).FirstOrDefault().Name, Notes = query3.Where(z => z.ConcernId == x.Id && z.Concern == "people").OrderByDescending(z => z.Id).ToList() }).ToList(); } card.data = card.data.OrderBy(x => x.Nom).ToList(); return(card); }
public static KnowHow GetSearchForKnowledge(string searchFor) { KnowHow knowledge = new KnowHow() { caption = "Base de connaissances", headers = new string[] { "Id", "Description", "Créée le", "Modifiée le" }, types = new string[] { "number", "string", "datetime", "datetime" }, props = new string[] { "Id", "Subject", "Creation", "Modification" } }; using (var dbContext = new QuickToDosEntities()) { IQueryable <Knowledge> query; query = dbContext.Knowledges.Where(x => x.Subject.Contains(searchFor)); knowledge.data = query.Select(x => new DataForKnowledge { Id = x.Id, Subject = x.Subject, Creation = x.Creation, Modification = x.Modification, Body = x.Body }).ToList(); } knowledge.data = knowledge.data.OrderByDescending(x => x.Id).ToList(); return(knowledge); }
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(); } } }
public static List <File> getFiles(int id, string concern) { List <File> files = new List <File>(); using (var dbContext = new QuickToDosEntities()) { files = dbContext.Files.Where(x => x.ExtId == id && x.Concern == concern).ToList(); } return(files); }
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); }
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(); } }
public static List <htmlSelect> GetPositions() { List <htmlSelect> positions = new List <htmlSelect>(); using (var dbContext = new QuickToDosEntities()) { positions = dbContext.Positions.Where(x => x.Id > 0).Select(y => new htmlSelect { key = y.Id, value = y.Name }).ToList(); } return(positions); }
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); }
public static string GetPhoto(int Id) { string Photo = ""; using (var dbContext = new QuickToDosEntities()) { Person aPerson = dbContext.People.Find(Id); if (aPerson != null) { Photo = aPerson.Photo; } } return(Photo); }
public static PeopleObject GetSearchForPeople(string searchFor) { PeopleObject card = new PeopleObject() { caption = "Personnages", headers = new string[] { "Id", "Nom", "Prénom", "Position", "Mobile", "Email" }, types = new string[] { "number", "string", "string", "string", "string" }, props = new string[] { "Id", "Nom", "Prenom", "Position", "Mobile", "Email" } }; using (var dbContext = new QuickToDosEntities()) { IQueryable <Position> query2 = dbContext.Positions; IQueryable <Note> query3 = dbContext.Notes; List <int?> Ids = new List <int?>(); var NoteList = dbContext.Notes.Where( x => x.Body.Contains(searchFor) && x.Concern == "people" ).ToList(); foreach (var note in NoteList) { Ids.Add(note.ConcernId); } IQueryable <Person> query = dbContext.People.Where( x => x.Nom.Contains(searchFor) || x.Prenom.Contains(searchFor) || x.Email.Contains(searchFor) || Ids.Contains(x.Id) ); card.data = query.Select(x => new DataForPeople { Id = x.Id, Nom = x.Nom, Prenom = x.Prenom, IdPosition = x.IdPosition != null ? (int)x.IdPosition : 0, Email = x.Email, Mobile = x.Mobile, Photo = x.Photo != null ? x.Photo : "", Position = query2.Where(y => y.Id == x.IdPosition).FirstOrDefault().Name, Notes = query3.Where(z => z.ConcernId == x.Id && z.Concern == "people").ToList() }).ToList(); } card.data = card.data.OrderByDescending(x => x.Id).Take(30).ToList(); return(card); }
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); }
public static int CalcMinutes(int JobId) { int nrMinutes = 0; using (var dbContext = new QuickToDosEntities()) { List <Break> results = dbContext.Breaks.Where(x => x.ToDoId == JobId).ToList(); if (results != null) { foreach (Break chunk in results) { if (chunk.Start != null && chunk.End != null) { nrMinutes += CalcOneTimeChunk((DateTime)chunk.Start, (DateTime)chunk.End); } } } } return(nrMinutes); }
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); } }
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); }
public static Work GetData(string searchFor) { Work work = new Work() { caption = "Work in progress", headers = new string[] { "Id", "Description", "Begin", "End", "Reference", "Branch", "Planned", "Duration", "Done", "Status" }, types = new string[] { "number", "string", "datetime", "datetime", "string", "string", "number", "number", "boolean", "string" }, props = new string[] { "Id", "Description", "Begin", "End", "Reference", "Branch", "Planned", "Duration", "Done", "Status" }, appraisal = getStatusList() }; using (var dbContext = new QuickToDosEntities()) { IQueryable <toDo> query; if (searchFor.Length == 0) { query = dbContext.toDos.Where(x => x.DontShow != true); query = query.OrderByDescending(x => x.Id).Take(12); } else { TimeToken result = GetToken(searchFor); if (result.Token == "none") { List <int?> Ids = new List <int?>(); var NoteList = dbContext.Notes.Where(x => x.Body.Contains(searchFor) && x.Concern == "work").ToList(); foreach (var note in NoteList) { Ids.Add(note.ConcernId); } query = dbContext.toDos.Where(x => x.DontShow != true && ( x.Branch.Contains(searchFor) || x.Notes.Contains(searchFor) || x.Reference.Contains(searchFor) || Ids.Contains(x.Id) )); } else { //Name = "last week", //Token = "week", //When = -1 DateTime start = DateTime.Now; DateTime finish = DateTime.Now; if (result.Token == "day") { start = DateTime.Today.AddDays(result.When); finish = start.AddDays(1).AddSeconds(-1); } else if (result.Token == "week") // to be continued { var day = (int)start.DayOfWeek; if (day == 0) { day = 7; } var delta = 1 - day + result.When * 7; start = DateTime.Today.AddDays(delta); finish = start.AddDays(7).AddSeconds(-1); } else if (result.Token == "month") // to be continued { var day = start.Day; // day in month var delta = 1 - day; start = DateTime.Today.AddMonths(result.When).AddDays(delta); delta = delta + 6; finish = start.AddMonths(1).AddDays(-1); } query = dbContext.toDos.Where(x => x.DontShow != true && (x.Begin >= start && x.Begin <= finish)); } } work.data = query.Select(x => new DataForJobs { Id = x.Id, Description = x.Description, Begin = x.Begin, End = x.End, Reference = x.Reference, Duration = x.Duration, Done = x.Done, Notes = x.Notes, Planned = x.Planned, Branch = x.Branch == null ? "" : x.Branch, Appraisal = x.Status, AppraisalNote = x.Status_Note == null ? "" : x.Status_Note, ExtNotes = dbContext.Notes.Where(y => y.ConcernId == x.Id && y.Concern == "work").OrderByDescending(y => y.Id).ToList(), TimeChunks = x.Breaks.Where(y => y.ToDoId == x.Id) .Select(y => new TimeChunkInfo { Id = y.Id, Begin = y.Start, End = y.End }).ToList() }).ToList(); } foreach (DataForJobs job in work.data) { job.Files = getFiles(job.Id, "work"); if (job.End != null) { job.Status = job.Appraisal_Str; } else { var item = job.TimeChunks.FirstOrDefault(i => i.End == null); if (item != null) { job.Status = "Running"; } else { job.Status = "Pending"; } } } work.data = work.data.OrderByDescending(x => x.Id).ToList(); return(work); }
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); }