public ActionResult Hire(int id, int[] TechId)
        {
            string mail = User.Identity.Name;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                User    usr = db.Users.Find(id);
                Company cmp = db.Companies.First(x => x.Email.Equals(mail));

                if (db.WorkingAts.Any(x => x.UserId == id && x.CompanyId == cmp.CompanyId && x.Until == null))
                {
                    TempData["Status"] = "The selected employee is already working at your company!";
                    return(RedirectToAction("SearchEmployees", "Account"));
                }

                if (usr.MadeUp == true)
                {
                    foreach (int t in TechId)
                    {
                        WorkingAt job = new WorkingAt();
                        job.Since       = DateTime.Now;
                        job.Until       = null;
                        job.TechId      = t;
                        job.UserId      = usr.UserId;
                        job.CompanyId   = cmp.CompanyId;
                        job.CompanyName = cmp.CompanyName;
                        job.Description = "Automatically generated description";
                        db.WorkingAts.Add(job);
                        db.SaveChanges();
                    }
                }
                else
                {
                    User       cmp2 = db.Users.First(x => x.Email.Equals(mail));
                    JobRequest r    = new JobRequest();
                    r.DateOfRequest = DateTime.Now;
                    r.SenderId      = cmp2.UserId;
                    r.ReceiverId    = usr.UserId;
                    r.Status        = "New";
                    string techs = "";
                    foreach (int t in TechId)
                    {
                        techs += t.ToString() + ",";
                    }
                    techs.Remove(techs.Length - 1, 1);
                    r.Techs = techs;
                    db.JobRequests.Add(r);
                    db.SaveChanges();
                    SendMail(mail, 3, usr.Email);
                }

                SendMail(mail, 4, "");
            }

            return(RedirectToAction("MyCompanyProfile", "Account"));
        }
Exemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id, string reason)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                User usr = db.Users.Find(id);

                string mail = usr.Email;

                if (usr != null)
                {
                    db.Users.Remove(usr);

                    if (usr.RoleId == 103)
                    {
                        Company cmp = db.Companies.Single(x => x.Email == usr.Email);

                        db.Companies.Remove(cmp);
                    }

                    if (usr.MadeUp == false)
                    {
                        SendMail(mail, 3, reason);
                    }
                    db.SaveChanges();
                    TempData["Status"] = "User/company deleted";

                    return(Redirect("~/Admin/UserAndCompany/Index"));
                }
            }

            ViewBag.Result = "The user was not deleted. Something went wrong.";
            return(View());
        }
Exemplo n.º 3
0
        public ActionResult ChangeStatus(int id, string status)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                User mod = db.Users.Find(id);

                if (status == "true")
                {
                    mod.Blocked = false;
                }
                else
                {
                    mod.Blocked = true;
                }

                ViewBag.Result = "The new moderator " + mod.FirstName + " " + mod.LastName + "'s status is changed.";
                if (mod.MadeUp == false)
                {
                    SendMail(mod.Email, 2, "");
                }
                db.SaveChanges();
            }

            return(Redirect("~/Admin/Moderator/Index"));
        }
        public ActionResult RequestJob(int id)
        {
            string mail = User.Identity.Name;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                User    usr = db.Users.FirstOrDefault(x => x.Email.Equals(mail) == true);
                Company cmp = db.Companies.Find(id);
                if (db.WorkingAts.FirstOrDefault(x => x.CompanyId == cmp.CompanyId && x.UserId == usr.UserId && x.Until == null) != null)
                {
                    TempData["Status"] = "You already work here, you can't ask for this job.";
                    return(RedirectToAction("MyProfile", "Account"));
                }

                if (cmp.MadeUp == true)
                {
                    WorkingAt job = new WorkingAt
                    {
                        Since       = DateTime.Now,
                        Until       = null,
                        CompanyId   = cmp.CompanyId,
                        CompanyName = cmp.CompanyName,
                        Description = "",
                        UserId      = usr.UserId,
                        TechId      = 101,
                        Tech        = db.Technologies.Find(101),
                        User        = db.Users.Find(usr.UserId),
                        Company     = db.Companies.Find(cmp.CompanyId)
                    };
                    WorkingAtVM jobToSend = new WorkingAtVM(job)
                    {
                        PathId = 101,
                        TechId = new int[1]
                    };
                    jobToSend.TechId[0]     = 101;
                    jobToSend.Technology    = new string[1];
                    jobToSend.Technology[0] = "Ruby";
                    db.WorkingAts.Add(job);
                    db.SaveChanges();

                    return(RedirectToAction("EditHistory", "Account", jobToSend));
                }

                else
                {
                    JobRequest rqst = new JobRequest();
                    rqst.DateOfRequest = DateTime.Now;
                    rqst.SenderId      = usr.UserId;
                    rqst.ReceiverId    = db.Users.First(x => x.Email.Equals(cmp.Email)).UserId;
                    rqst.Status        = "New";

                    SendMail(cmp.Email, 3, "");

                    TempData["Status"] = "You sent the request. You won't be able to send another requests to any company for another week, or until the company responds.";

                    return(RedirectToAction("MyProfile", "Account"));
                }
            }
        }
Exemplo n.º 5
0
        public ActionResult ChangeStatus(int id, string status)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                User usr = db.Users.Find(id);

                Company cmp = null;

                if (usr.RoleId == 103)
                {
                    cmp = db.Companies.Single(x => x.Email == usr.Email);
                }

                if (usr != null)
                {
                    if (status == "true")
                    {
                        usr.Blocked = false;

                        if (usr.RoleId == 103)
                        {
                            cmp.Blocked = false;
                        }

                        if (usr.MadeUp == false)
                        {
                            SendMail(usr.Email, 2, "");
                        }
                    }
                    else
                    {
                        usr.Blocked = true;

                        if (usr.RoleId == 103)
                        {
                            cmp.Blocked = true;
                        }

                        if (usr.MadeUp == false)
                        {
                            SendMail(usr.Email, 1, "");
                        }
                    }

                    db.SaveChanges();

                    ViewBag.Result = "The data have been changed.";
                }
            }

            return(Redirect("~/Admin/UserAndCompany/Index"));
        }
Exemplo n.º 6
0
 public ActionResult DeleteConfirmed(int id, string reason)
 {
     using (ITExpertsContext db = new ITExpertsContext())
     {
         User u = db.Users.Find(id);
         db.Users.Remove(u);
         db.SaveChanges();
         ViewBag.Result = "The moderator " + u.FirstName + " " + u.LastName + " was deleted.";
         if (u.MadeUp == false)
         {
             SendMail(u.Email, 1, reason);
         }
         return(Redirect("~/Admin/Moderator/Index"));
     }
 }
Exemplo n.º 7
0
        public int DeletePath(int id)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                DevPath row = db.DevPaths.Find(id);

                if (row != null)
                {
                    db.DevPaths.Remove(row);
                    db.SaveChanges();
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
        }
Exemplo n.º 8
0
        public int UpdatePath(DevPathVM model)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                DevPath row = db.DevPaths.Find(model.PathId);

                if (row != null)
                {
                    row.PathName = model.PathName;
                    db.SaveChanges();
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
        }
Exemplo n.º 9
0
        public int UpdateTech(TechnologyVM model)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                Technology row = db.Technologies.Find(model.TechId);

                if (row != null)
                {
                    row.TechDescription = model.TechDescription;
                    row.TechName        = model.TechName;
                    db.SaveChanges();
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
        }
Exemplo n.º 10
0
        public ActionResult AddModerator(ModeratorVM model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Result = null;
                return(View("AddModerator", model));
            }

            if (!model.Password.Equals(model.ConfirmPassword))
            {
                ModelState.AddModelError("", "The password and the confirmation do not match!");
                return(View("AddModerator", model));
            }

            using (ITExpertsContext db = new ITExpertsContext())
            {
                if (db.Users.Any(x => x.Email.Equals(model.Email)))
                {
                    ModelState.AddModelError("", "That email has already been taken!");
                    ViewBag.Result = null;
                    return(View("AddModerator", model));
                }

                User newMod = new User()
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Password  = model.Password,
                    Email     = model.Email,
                    RoleId    = 101,
                    Active    = true,
                    Blocked   = false
                };

                db.Users.Add(newMod);
                db.SaveChanges();
            }

            ViewBag.Result = "The new moderator was added.";

            return(Redirect("~/Admin/Moderator/Index"));
        }
Exemplo n.º 11
0
        public int AddPath(DevPathVM model)
        {
            DevPath row = new DevPath()
            {
                PathId   = model.PathId,
                PathName = model.PathName
            };

            using (ITExpertsContext db = new ITExpertsContext())
            {
                try
                {
                    db.DevPaths.Add(row);
                    db.SaveChanges();
                    return(1);
                }
                catch (Exception)
                {
                    return(0);
                }
            }
        }
Exemplo n.º 12
0
        public int AddTech(TechnologyVM model)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                try
                {
                    Technology row = new Technology()
                    {
                        TechName        = model.TechName,
                        TechDescription = model.TechDescription,
                        PathId          = model.PathId
                    };

                    db.Technologies.Add(row);
                    db.SaveChanges();
                    return(1);
                }
                catch (Exception)
                {
                    return(0);
                }
            }
        }
Exemplo n.º 13
0
 public int DeleteTech(int techId)
 {
     if (techId > 0)
     {
         using (ITExpertsContext db = new ITExpertsContext())
         {
             try
             {
                 Technology row = db.Technologies.Find(techId);
                 db.Technologies.Remove(row);
                 db.SaveChanges();
                 return(1);
             }
             catch (Exception)
             {
                 return(0);
             }
         }
     }
     else
     {
         return(0);
     }
 }
        public JsonResult FireEmployee(int userId, int companyId, string reason)
        {
            try
            {
                using (ITExpertsContext db = new ITExpertsContext())
                {
                    foreach (WorkingAt job in db.WorkingAts.Where(x => x.CompanyId == companyId && x.UserId == userId && x.Until == null).ToList())
                    {
                        job.Until = DateTime.Now;
                    }

                    User usr = db.Users.Find(userId);

                    if (usr.MadeUp != true)
                    {
                        SendMail(usr.Email, 1, reason);
                    }

                    Company cmp = db.Companies.Find(companyId);

                    if (cmp.MadeUp != true)
                    {
                        reason = usr.FirstName + " " + usr.LastName;
                        SendMail(cmp.Email, 2, reason);
                    }

                    db.SaveChanges();
                }

                return(Json("1", JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json("0", JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 15
0
        public ActionResult Quit(int id)
        {
            string mail = User.Identity.Name;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                User    usr = db.Users.First(x => x.Email.Equals(mail));
                Company cmp = db.Companies.Find(id);

                List <WorkingAt> list = null;
                list = db.WorkingAts.ToList().Where(x => x.CompanyId == cmp.CompanyId && x.UserId == usr.UserId && x.Until == null).ToList();

                if (list != null)
                {
                    foreach (WorkingAt job in list)
                    {
                        job.Until = DateTime.Now;
                    }

                    TempData["Status"] = "You decided to quit your current job. We honestly hope it was a wise decision. Good luck!";
                    SendMail(usr.Email, 1, "");
                    db.SaveChanges();

                    if (cmp.MadeUp != true)
                    {
                        SendMail(usr.Email, 2, cmp.Email);
                    }
                }
                else
                {
                    TempData["Status"] = "You do not currently work there!";
                }
            }

            return(RedirectToAction("MyProfile", "Account"));
        }