internal static void FinishTask(UnityOfWork unit, Task selectedTask) { var task = unit.Task.GetAll().FirstOrDefault(T => T.Task_Id == selectedTask.Task_Id); task.Done = true; unit.Complete(); }
public static bool AddProject(string id, string descripton, string deadline) { var ParsedDeadLine = new DateTime(); try { ParsedDeadLine = DateTime.Parse(deadline); } catch (Exception) { return(false); } var unit = new UnityOfWork(new ProjectTracerEntities()); unit.Project.Add(new Project() { Project_ID = id, Description = descripton, DeadLine = ParsedDeadLine, Result = "notregistered", }); try { unit.Complete(); unit.Dispose(); return(true); } catch (Exception e) { return(false); } }
public void RemoveAuthor(Author Author) { using (var unity = new UnityOfWork()) { new AuthorBdRepository(unity).Remove(Author); unity.Complete(); } }
public static void RemoveTask(UnityOfWork unit, Task Tasks) { var taskToDelete = unit.Task.GetAll().Where(SearchedTask => SearchedTask.Task_Id == Tasks.Task_Id).FirstOrDefault(); unit.Task.Remove(taskToDelete); unit.Complete(); }
internal static bool ReleaseTask(UnityOfWork unit, Task selectedTask, Developer myDeveloper) { var task = unit.Task.GetAll().FirstOrDefault(T => T.Task_Id == selectedTask.Task_Id); task.DeveloperOnTask = null; unit.Complete(); return(unit.Task.GetAll().FirstOrDefault(T => T.Task_Id == selectedTask.Task_Id).DeveloperOnTask == null); }
public static void RemoveProject(UnityOfWork unit, Project project) { var ProjectToDelete = unit.context .Project .Include("Document") .Include("Task") .FirstOrDefault(searchedProject => searchedProject.Project_ID == project.Project_ID); var documents = unit.Document.GetAll() .Where(d => d.Project_Id == ProjectToDelete.Project_ID) .ToList(); unit.Document.RemoveRange(documents); unit.Complete(); var tasks = unit.context.Task .Where(t => t.Project_Id == ProjectToDelete.Project_ID) .ToList(); unit.Task.RemoveRange(tasks); unit.Complete(); unit.Team .GetAll() .Where(t => t.Project.Contains(ProjectToDelete)) .ToList() .ForEach(t => t.Project.Remove(ProjectToDelete)); unit.Complete(); unit.Client .GetAll() .Where(c => c.Project .Contains(ProjectToDelete)) .ToList() .ForEach(c => c.Project.Remove(ProjectToDelete)); unit.Complete(); unit.Project.Remove(ProjectToDelete); unit.Complete(); MessageBox.Show("Project Deleted"); }
internal static void RemoveDevFromTeam(UnityOfWork unit, string devId, int TeamId) { unit.Developer .GetAll() .FirstOrDefault(D => D.Id == devId) .Team .Remove(unit.Team.GetAll().FirstOrDefault(T => T.Team_ID == TeamId)); unit.Complete(); }
public void RemoveBook(int bookId) { using (var unity = new UnityOfWork()) { new BookBdRepository(unity).Remove(new Book() { Id = bookId }); unity.Complete(); } }
public ActionResult Create([Bind(Include = "Id,Name,Description,Level,FullPrice")] Course course) { if (ModelState.IsValid) { unityOfWork.Courses.Add(course); unityOfWork.Complete(); return(RedirectToAction("Index")); } return(View(course)); }
internal static bool TakeTask(UnityOfWork unit, Task selectedTask, Developer myDeveloper) { if (selectedTask.DeveloperOnTask == null) { var task = unit.Task.GetAll().FirstOrDefault(T => T.Task_Id == selectedTask.Task_Id); task.DeveloperOnTask = myDeveloper.Id; unit.Complete(); return(true); } return(false); }
public static void UpdateTask(UnityOfWork unit, Task task) { Task mytask = unit.Task. GetAll() .Where(searchedTasks => searchedTasks.Project_Id == task.Project_Id) .FirstOrDefault(t => t.Task_Id == task.Task_Id); mytask.Task_Id = task.Task_Id; mytask.Description = task.Description; mytask.DeadLine = task.DeadLine; unit.Complete(); }
public Book GetBookById(object id) { Book book = null; using (var unity = new UnityOfWork()) { book = new BookBdRepository(unity).GetById(id); unity.Complete(); } return(book); }
public Author GetAuthorById(object id) { Author Author = null; using (var unity = new UnityOfWork()) { Author = new AuthorBdRepository(unity).GetById(id); Author.AddName(new SubjectBdRepository(unity).GetNameOfAuthor(Author)); unity.Complete(); } return(Author); }
public Book GetBookById(object id) { Book book = null; using (var unity = new UnityOfWork()) { book = new BookBdRepository(unity).GetById(id); book.AddSubjects(new SubjectBdRepository(unity).GetSubjectsOfABook(book)); book.AddAuthors(new AuthorBdRepository(unity).GetAuthorsOfABook(book)); unity.Complete(); } return(book); }
public IEnumerable <string> AddAuthor(Author Author) { IEnumerable <string> errors = Author.Validate(); if (!errors.Any()) { using (var unity = new UnityOfWork()) { new AuthorBdRepository(unity).Add(Author); unity.Complete(); } } return(errors); }
public IEnumerable <string> AddBook(Book book) { IEnumerable <string> errors = book.Validate(); if (!errors.Any()) { using (var unity = new UnityOfWork()) { new BookBdRepository(unity).Add(book); unity.Complete(); } } return(errors); }
internal static void RegistrateTeam(string devId, string seniorId, UnityOfWork unit) { var teamId = unit.Team.GetAll().Count() + 1; unit.Team .Add(new Team() { Team_ID = teamId }); unit.Complete(); unit.Senior .GetAll() .FirstOrDefault(S => S.Id == seniorId) .Team.Add(unit.Team.GetAll().FirstOrDefault(T => T.Team_ID == teamId)); unit.Complete(); unit.Developer .GetAll() .FirstOrDefault(D => D.Id == devId) .Team .Add(unit.Team.GetAll().FirstOrDefault(T => T.Team_ID == teamId)); unit.Complete(); }
static void Main(string[] args) { using (UnityOfWork unityOfWork = new UnityOfWork(new NorthwindEntities())) { //Example 1 var employee = unityOfWork.Employees.Get(1); Console.WriteLine($"Firs Name: {employee.FirstName}"); //Example 2 var employees = unityOfWork.Employees.GetTopEmployees(4); unityOfWork.Complete(); //Save alle änderungen in DB } }
public IEnumerable <Author> GetAllAuthor() { IEnumerable <Author> Author; using (UnityOfWork unity = new UnityOfWork()) { Author = new AuthorBdRepository(unity).GetAll(); var subjectRep = new SubjectBdRepository(unity); var authorRep = new AuthorBdRepository(unity); foreach (var Authors in Author) { Authors.AddName(subjectRep.GetSNameOfAuthors(Author)); Authors.AddAuthors(authorRep.GetAuthorsOfAuthor(Author)); } unity.Complete(); } return(Author); }
public IEnumerable <Book> GetAllBooks() { IEnumerable <Book> books; using (UnityOfWork unity = new UnityOfWork()) { books = new BookBdRepository(unity).GetAll(); var subjectRep = new SubjectBdRepository(unity); var authorRep = new AuthorBdRepository(unity); foreach (var book in books) { book.AddSubjects(subjectRep.GetSubjectsOfABook(book)); book.AddAuthors(authorRep.GetAuthorsOfABook(book)); } unity.Complete(); } return(books); }
public static bool AddTask(string descripton, string deadline, string project_Id) { if (project_Id == null) { MessageBox.Show("Not selected project"); return(false); } var parseDeadLine = new DateTime(); try { parseDeadLine = DateTime.Parse(deadline); } catch (Exception) { MessageBox.Show("Incorrect DeadLine"); return(false); } var unit = new UnityOfWork(new ProjectTracerEntities()); unit.Task.Add(new Task() { Description = descripton, DeadLine = parseDeadLine, Project_Id = project_Id }); try { unit.Complete(); return(true); } catch (Exception) { MessageBox.Show("Error ocurred saving changes, please try later"); return(false); } }
public static bool RegisterInServer(IUser user) { try { var UnitOFWork = new UnityOfWork(new ProjectTracerEntities()); var projects = UnitOFWork.Project.GetAll().ToList(); switch (user.GetType().Name) { case "Client": if (user.InvitationCode != string.Empty) { var decryptedId = Encrypt.DecryptString(user.InvitationCode, "Pass"); foreach (var project in projects) { if (project.Project_ID == decryptedId) { // Add the new client UnitOFWork.Client.Add( new Client() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") } ); UnitOFWork.Complete(); //Relate client with the new project UnitOFWork.Client .GetAll() .FirstOrDefault(c => c.Id == user.Id) .Project .Add( UnitOFWork.Project .GetAll() .FirstOrDefault(P => P.Project_ID == decryptedId) ); UnitOFWork.Complete(); return(true); } } MessageBox.Show("Incorrect Registration Code"); return(false); } else { UnitOFWork.Client.Add(new Client() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); } break; case "Developer": if (user.InvitationCode != string.Empty) { var decryptedId = Encrypt.DecryptString(user.InvitationCode, "Pass"); foreach (var project in projects) { if (project.Project_ID == decryptedId) { // Add the new dev UnitOFWork.Developer .Add( new Developer() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") } ); UnitOFWork.Complete(); //No teams in this project? ok, then we create one var teamId = UnitOFWork.Team.GetAll().Count() + 1; if (UnitOFWork.Project .GetAll() .FirstOrDefault(p => p.Project_ID == project.Project_ID) .Team.Count == 0) { // Add one team to teams UnitOFWork.Team .Add(new Team() { Team_ID = teamId }); UnitOFWork.Complete(); //Relate this team to our project UnitOFWork.Team .GetAll() .FirstOrDefault(t => t.Team_ID == teamId) .Project .Add(UnitOFWork.Project.GetAll().FirstOrDefault(t => t.Project_ID == project.Project_ID)); UnitOFWork.Complete(); //Add our Team to our Developer UnitOFWork.Developer.GetAll().FirstOrDefault(d => d.Id == user.Id) .Team .Add( UnitOFWork.Team .GetAll() .FirstOrDefault(t => t.Team_ID == teamId)); UnitOFWork.Complete(); } else { //In case that there is already teams working on the project we add the developer to the first UnitOFWork.Project .GetAll() .FirstOrDefault(p => p.Project_ID == project.Project_ID) .Team .FirstOrDefault() .Developer .Add(UnitOFWork.Developer.GetAll().FirstOrDefault(d => d.Id == user.Id)); UnitOFWork.Complete(); } UnitOFWork.Complete(); MessageBox.Show("Developer registrated"); return(true); } } MessageBox.Show("Incorrect Registration Code"); return(false); } else { UnitOFWork.Developer.Add(new Developer() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); } break; case "Senior": UnitOFWork.Senior.Add(new Senior() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); break; case "Admin": UnitOFWork.Administrator.Add(new Administrator() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); break; default: break; } return(true); } catch (Exception) { MessageBox.Show("Error in sever:"); return(false); } }
public static bool RegisterInServerProc(IUser user) { SqlConnection sq = new SqlConnection($@"data source=DESKTOP-KGC5T7J;initial catalog=ProjectTracer;integrated security=True"); SqlCommand scmd = new SqlCommand($"EXEC dbo.RegisterInServer @UserName = '******', @RoleName = '{user.GetType().Name}'", sq); scmd.Parameters.Clear(); sq.Open(); try { var UnitOFWork = new UnityOfWork(new ProjectTracerEntities()); var projects = UnitOFWork.Project.GetAll().ToList(); switch (user.GetType().Name) { case "Client": if (user.InvitationCode != string.Empty) { var decryptedId = Encrypt.DecryptString(user.InvitationCode, "Pass"); foreach (var project in projects) { if (project.Project_ID == decryptedId) { scmd.ExecuteScalar(); sq.Close(); // Add the new client UnitOFWork.Client.Add( new Client() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") } ); UnitOFWork.Complete(); //Relate client with the new project UnitOFWork.Client .GetAll() .FirstOrDefault(c => c.Id == user.Id) .Project .Add( UnitOFWork.Project .GetAll() .FirstOrDefault(P => P.Project_ID == decryptedId) ); UnitOFWork.Complete(); return(true); } } MessageBox.Show("Incorrect Registration Code"); return(false); } else { scmd.ExecuteScalar(); sq.Close(); UnitOFWork.Client.Add(new Client() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); } break; case "Developer": if (user.InvitationCode != string.Empty) { var decryptedId = Encrypt.DecryptString(user.InvitationCode, "Pass"); foreach (var project in projects) { if (project.Project_ID == decryptedId) { scmd.ExecuteScalar(); sq.Close(); // Add the new dev UnitOFWork.Developer .Add( new Developer() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") } ); UnitOFWork.Complete(); //No teams in this project? ok, then we create one var teamId = UnitOFWork.Team.GetAll().Count() + 1; if (UnitOFWork.Project .GetAll() .FirstOrDefault(p => p.Project_ID == project.Project_ID) .Team.Count == 0) { // Add one team to teams UnitOFWork.Team .Add(new Team() { Team_ID = teamId }); UnitOFWork.Complete(); //Relate this team to our project UnitOFWork.Team .GetAll() .FirstOrDefault(t => t.Team_ID == teamId) .Project .Add(UnitOFWork.Project.GetAll().FirstOrDefault(t => t.Project_ID == project.Project_ID)); UnitOFWork.Complete(); //Add our Team to our Developer UnitOFWork.Developer.GetAll().FirstOrDefault(d => d.Id == user.Id) .Team .Add( UnitOFWork.Team .GetAll() .FirstOrDefault(t => t.Team_ID == teamId) ); UnitOFWork.Complete(); } else { //In case that there is already teams working on the project we add the developer to the first UnitOFWork.Project .GetAll() .FirstOrDefault(p => p.Project_ID == project.Project_ID) .Team .FirstOrDefault() .Developer .Add(UnitOFWork.Developer.GetAll().FirstOrDefault(d => d.Id == user.Id)); UnitOFWork.Complete(); } UnitOFWork.Complete(); MessageBox.Show("Developer registrated"); return(true); } } MessageBox.Show("Incorrect Registration Code"); return(false); } else { scmd.ExecuteScalar(); sq.Close(); UnitOFWork.Developer.Add(new Developer() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); } break; case "Senior": scmd.ExecuteScalar(); sq.Close(); UnitOFWork.Senior.Add(new Senior() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); break; case "Admin": scmd.ExecuteScalar(); sq.Close(); UnitOFWork.Administrator.Add(new Administrator() { Id = user.Id, Password = Encrypt.EncryptString(user.Password, "Pass") }); UnitOFWork.Complete(); break; default: break; } return(true); } catch (Exception) { MessageBox.Show("Error in sever:"); sq.Close(); return(false); } }