public bool AddPartnership(HiringCompany hc, OutsourcingCompany oc)
        {
            using (var access = new AccessDB())
            {
                Partnership pr = access.PrartnershipAction.FirstOrDefault(f => f.HiringCompany.CompanyIdThr.Equals(hc.CompanyIdThr) && f.OutsourcingCompany.Id.Equals(oc.Id));

                if (pr == null)
                {
                    Partnership partnership = new Partnership();
                    partnership.HiringCompany      = hc;
                    partnership.OutsourcingCompany = oc;

                    access.HcActions.Attach(partnership.HiringCompany);
                    access.OcActions.Attach(partnership.OutsourcingCompany);
                    access.PrartnershipAction.Add(partnership);

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully added partnership.");
                        return(true);
                    }

                    Log.Warn("Failed to add partnership");
                    return(false);
                }
                else
                {
                    Log.Warn("Partnership already exists.");
                    return(false);
                }
            }
        }
        public bool AddCompany(HiringCompany company)
        {
            Log.Debug("Enter AddCompany method.");
            using (var access = new AccessDB())
            {
                HiringCompany cm = access.HcActions.FirstOrDefault(f => f.CompanyIdThr.Equals(company.CompanyIdThr));
                if (cm == null)
                {
                    access.HcActions.Add(company);

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully updated DB.");
                        return(true);
                    }
                    Log.Warn("Failed to update DB.");
                    return(false);
                }
                else
                {
                    Log.Warn("Company already exists in DB");
                    return(false);
                }
            }
        }
Beispiel #3
0
        public bool AddUserStory(UserStory us)
        {
            using (var access = new AccessDB())
            {
                Log.Info("Enter AddUserStory");
                UserStory uStory = access.UsAction.FirstOrDefault(f => f.Name.Equals(us.Name));
                if (uStory == null)
                {
                    access.PrActions.Attach(us.Project);
                    access.UsAction.Add(us);

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfullye added user story to DB.");
                        return(true);
                    }
                    Log.Warn("Failed to add user story do DB.");
                    return(false);
                }
                else
                {
                    Log.Warn("User story allready exists in DB.");
                    return(false);
                }
            }
        }
Beispiel #4
0
        public bool ChangeUserStoryState(int id, UserStoryState state)
        {
            using (var access = new AccessDB())
            {
                Log.Info("Enter Change user story state");
                UserStory us = access.UsAction.FirstOrDefault(f => f.Id == id);

                if (us != null)
                {
                    us.UserStoryState = state;

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully changed user story state.");
                        return(true);
                    }
                    else
                    {
                        Log.Warn("Failed to changed user story state.");
                        return(false);
                    }
                }
                else
                {
                    Log.Warn("User story doesn't exists in DB.");
                    return(false);
                }
            }
        }
        /// <summary>
        ///     DB insert action
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public bool AddEmployee(Employee action)
        {
            Log.Debug("Enter AddEmployee method.");
            using (AccessDB access = new AccessDB())
            {
                Employee em = access.Actions.FirstOrDefault(f => f.Username.Equals(action.Username));
                if (em == null)
                {
                    ///In order to avoid the duplication you must attach the related entity to the context
                    access.HcActions.Attach(action.HiringCompanyId);

                    access.Actions.Add(action);

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("SaveChanges to DB success.");
                        return(true);
                    }
                    Log.Warn("SaveChanges return 0");
                    return(false);
                }
                else
                {
                    Log.Warn("User  with username you are trying to add to the database, already exists!");
                    return(false);
                }
            }
        }
Beispiel #6
0
        public bool UpdateUserStory(UserStory us)
        {
            using (var access = new AccessDB())
            {
                UserStory u = access.UsAction.FirstOrDefault(f => f.Name.Equals(us.Name));

                if (u != null)
                {
                    u.IdFromOcDB        = us.Id;
                    u.Description       = us.Description;
                    u.Name              = us.Name;
                    u.Progress          = us.Progress;
                    u.UserStoryState    = us.UserStoryState;
                    u.WeightOfUserStory = us.WeightOfUserStory;

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully update user story.");
                        return(true);
                    }
                    else
                    {
                        Log.Warn("Failed to update user story.");
                        return(false);
                    }
                }
                else
                {
                    Log.Warn("User story for specified name doesn't exist.");
                    return(false);
                }
            }
        }
        public bool ChangeEmployeePosition(string username, string position)
        {
            Log.Debug("Enter ChangeEmployeePosition method.");
            using (var access = new AccessDB())
            {
                Employee em = access.Actions.FirstOrDefault(f => f.Username.Equals(username));
                if (em != null)
                {
                    //access.Actions.FirstOrDefault(f => f.Username == username).Position = position.ToString();
                    em.Position            = position.ToString();
                    access.Entry(em).State = System.Data.Entity.EntityState.Modified;

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully updated DB");
                        return(true);
                    }
                    Log.Warn("Failed to update DB");
                    return(false);
                }
                else
                {
                    Log.Warn("Employee with that username does not exist. Failed chainging position.");
                    return(false);
                }
            }
        }
        public bool EmployeeLogOut(string username)
        {
            Log.Debug("Enter EmployeeLogOut method.");
            using (var access = new AccessDB())
            {
                Employee emp = access.Actions.FirstOrDefault(f => f.Username.Equals(username));

                if (emp != null)
                {
                    //access.Actions.FirstOrDefault(f => f.Username.Equals(username)).Login = false;
                    emp.Login = false;
                    access.Entry(emp).State = System.Data.Entity.EntityState.Modified;

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully updated DB");
                        return(true);
                    }
                    Log.Warn("Failed to update DB");
                    return(false);
                }
                else
                {
                    Log.Warn("Employee with that username does not exist. Failed to logout.");
                    return(false);
                }
            }
        }
        public bool ChangeEmployeePassword(string username, string oldPassword, string newPassword)
        {
            Log.Debug("Enter ChangeEmployeePassword method.");
            using (var access = new AccessDB())
            {
                //access.Actions.FirstOrDefault(f => f.Username.Equals(username) && f.Password.Equals(oldPassword)).Password = newPassword;

                Employee em = access.Actions.FirstOrDefault(f => f.Username.Equals(username) && f.Password.Equals(oldPassword));
                if (em != null)
                {
                    em.Password            = newPassword;
                    em.PasswordUpadateDate = DateTime.Now;

                    access.Entry(em).State = System.Data.Entity.EntityState.Modified;

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully updated DB");
                        return(true);
                    }
                    Log.Warn("Failed to update DB");
                    return(false);
                }
                else
                {
                    Log.Warn("Employee with that username does not exist. Failed chainging password.");
                    return(false);
                }
            }
        }
        public bool AddProject(Project project)
        {
            Log.Debug("Enter AddProject method.");
            using (var access = new AccessDB())
            {
                Project proj = access.PrActions.FirstOrDefault(f => f.Name.Equals(project.Name));

                if (proj == null)
                {
                    if (project.Company != null)
                    {
                        access.OcActions.Attach(project.Company);
                    }
                    access.HcActions.Attach(project.HiringCompany);
                    access.Actions.Attach(project.ProductOwner);

                    access.PrActions.Add(project);

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully updated DB.");
                        return(true);
                    }
                    Log.Warn("Failed to update DB.");
                    return(false);
                }
                else
                {
                    Log.Warn("Project with specified name already exists in DB");
                    return(false);
                }
            }
        }
        public bool UpdateProject(Project p)
        {
            using (var access = new AccessDB())
            {
                Project pr = access.PrActions.FirstOrDefault(f => f.Name.Equals(p.Name));

                if (pr != null)
                {
                    pr.Approved    = p.Approved;
                    pr.Description = p.Description;
                    pr.EndDate     = p.EndDate;
                    pr.Ended       = p.Ended;
                    pr.Name        = p.Name;
                    pr.Progress    = p.Progress;
                    pr.EndDate     = p.EndDate;

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Project successfully updated.");
                        return(true);
                    }
                    return(false);
                }
                else
                {
                    Log.Warn("Project doesn't exists in DB");
                    return(false);
                }
            }
        }
        public bool MarkProjectEnded(Project p)
        {
            using (var access = new AccessDB())
            {
                Project project = access.PrActions.FirstOrDefault(f => f.Id == p.Id);

                if (project != null)
                {
                    project.Ended = true;

                    int i = access.SaveChanges();
                    if (i > 0)
                    {
                        Log.Info("Successfully marked project as ended.");
                        return(true);
                    }

                    Log.Warn("Failed to mark project as ended.");
                    return(false);
                }
                else
                {
                    Log.Warn("Project with specified id doesn't exists. ");
                    return(false);
                }
            }
        }
        public bool AddOutsourcingCompany(HiringCompanyData.OutsourcingCompany oCompany)
        {
            using (var access = new AccessDB())
            {
                HiringCompanyData.OutsourcingCompany oc = access.OcActions.FirstOrDefault(f => f.Name.Equals(oCompany.Name));
                if (oc == null)
                {
                    access.OcActions.Add(oCompany);

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully added outsourcing company into DB");
                        return(true);
                    }
                    return(false);
                }
                else
                {
                    Log.Warn("Outsourcing company already exists in DB");
                    return(false);
                }
            }
        }
        public bool UpdateEmployee(Employee employee)
        {
            Log.Debug("Enter UpdateEmployee method.");
            using (var access = new AccessDB())
            {
                //access.Actions.Attach(employee);
                Employee em = access.Actions.FirstOrDefault(f => f.Email.Equals(employee.Email));
                if (em != null)
                {
                    Log.Debug("Employee exists");
                    em.Email               = employee.Email;
                    em.EndTime             = employee.EndTime;
                    em.HiringCompanyId     = employee.HiringCompanyId;
                    em.Login               = employee.Login;
                    em.Name                = employee.Name;
                    em.Password            = employee.Password;
                    em.PasswordUpadateDate = employee.PasswordUpadateDate;
                    em.Position            = employee.Position;
                    em.StartTime           = employee.StartTime;
                    em.Surname             = employee.Surname;
                    em.Username            = employee.Username;



                    //access.Entry(employee).State = System.Data.Entity.EntityState.Modified;

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully updated DB");
                        return(true);
                    }
                    Log.Warn("Failed to update DB");
                    return(false);
                }
                else
                {
                    Log.Warn("Employee with that username does not exist. Failed updating employee.");
                    return(false);
                }
            }
        }
        public bool SetOcToProject(string projectName, int outsourcingCompanyId)
        {
            using (var access = new AccessDB())
            {
                Project p = access.PrActions.FirstOrDefault(f => f.Name.Equals(projectName));

                if (p != null)
                {
                    OutsourcingCompany oc = access.OcActions.FirstOrDefault(f => f.IdFromOutSourcingDB == outsourcingCompanyId);

                    if (oc != null)
                    {
                        p.Company = oc;
                        access.OcActions.Attach(p.Company);
                    }
                    else
                    {
                        Log.Warn("Outsourcing company doesn't exists.");
                    }

                    int i = access.SaveChanges();

                    if (i > 0)
                    {
                        Log.Info("Successfully assigned project to Outsourcing company.");
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    Log.Warn("Project doesn't exists.");
                    return(false);
                }
            }
        }