Exemplo n.º 1
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"));
        }
Exemplo n.º 2
0
        public static double ReturnSalary(int id)
        {
            double salary = 500;

            try
            {
                using (ITExpertsContext db = new ITExpertsContext())
                {
                    User user = db.Users.Find(id);
                    int  coefficient;
                    switch (user.EducationLevel)
                    {
                    case 2: coefficient = 25; break;

                    case 3: coefficient = 30; break;

                    case 4: coefficient = 35; break;

                    case 5: coefficient = 40; break;

                    case 6: coefficient = 50; break;

                    default: coefficient = 0; break;
                    }
                    List <WorkingAt> jobs         = db.WorkingAts.Where(x => x.UserId == id).ToList();
                    int[]            technologies = jobs.Select(x => x.TechId).Distinct().ToArray();
                    int numberOfTechs             = technologies.Count();
                    for (int i = 0; i < numberOfTechs; i++)
                    {
                        int months = 0;
                        foreach (WorkingAt job in jobs)
                        {
                            if (job.TechId == technologies[i])
                            {
                                TimeSpan time = new TimeSpan();

                                if (job.Until.HasValue)
                                {
                                    time = job.Until.Value - job.Since;
                                }
                                else
                                {
                                    time = DateTime.Now - job.Since;
                                }

                                months += time.Days / 30;
                            }
                        }

                        salary += ((float)months / 12) * coefficient;
                    }

                    return(salary);
                }
            }
            catch (Exception)
            {
                return(0);
            }
        }
Exemplo n.º 3
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());
        }
        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"));
                }
            }
        }
 public ActionResult CompanyList()
 {
     using (ITExpertsContext db = new ITExpertsContext())
     {
         List <CompanyVM> list = db.Companies.ToList().Select(x => new CompanyVM(x)).ToList();
         return(View(list));
     }
 }
 public ActionResult Hire(int id)
 {
     using (ITExpertsContext db = new ITExpertsContext())
     {
         UserVM usr = new UserVM(db.Users.Find(id));
         return(View(usr));
     }
 }
        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.º 8
0
        // GET: Admin/UserAndCompany
        public ActionResult Index()
        {
            List <UserVM> list = new List <UserVM>();

            using (ITExpertsContext db = new ITExpertsContext())
            {
                list = db.Users.ToList().Where(x => x.RoleId == 102 || x.RoleId == 103).Select(x => new UserVM(x)).ToList();
            }

            return(View(list));
        }
Exemplo n.º 9
0
        public JsonResult AllPaths()
        {
            List <DevPathVM> lista = new List <DevPathVM>();

            using (ITExpertsContext db = new ITExpertsContext())
            {
                lista = db.DevPaths.ToArray().Select(x => new DevPathVM(x)).ToList();

                return(Json(lista, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 10
0
        // GET: Admin/Moderator
        public ActionResult Index()
        {
            List <ModeratorVM> ModList = new List <ModeratorVM>();

            using (ITExpertsContext db = new ITExpertsContext())
            {
                ModList = db.Users.ToArray().Where(x => x.RoleId == 101).Select(x => new ModeratorVM(x)).ToList();
            }

            return(View(ModList));
        }
        private void SendMail(string mail, int type, string reason)
        {
            MailAddress sender   = new MailAddress("*****@*****.**", "Aleksandar Matic from ITExperts.com");
            MailAddress receiver = new MailAddress(mail);
            MailMessage msg      = new MailMessage(sender, receiver);

            msg.From = sender;
            msg.To.Add(receiver);
            msg.IsBodyHtml = true;
            NetworkCredential credentials = new NetworkCredential("*****@*****.**", "utbnwuvztkbgwpwj", "");
            SmtpClient        client      = new SmtpClient("smtp.gmail.com", 587);

            client.EnableSsl   = true;
            client.Credentials = credentials;

            User usr = null;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                usr = db.Users.Single(x => x.Email.Equals(mail));
            }

            if (usr != null)
            {
                //korisnik je otpusten, mail ide njemu
                if (type == 1)
                {
                    msg.Subject = "You have been fired, " + usr.FirstName + "!";
                    msg.Body    = "Dear " + usr.FirstName + " " + usr.LastName + ",<br>" +
                                  "it seems your current employer has fired you. We would suggest you send them email and see " +
                                  "if there's a possibility for some mistake. Their reason:<br>" + reason +
                                  "<br><br>Best regards,<br>Aleksandar Matic from ITExperts.com";
                }
                //korisnik je otpusten, mail ide kompaniji
                if (type == 2)
                {
                    msg.Subject = "You fired someone, " + usr.FirstName + "!";
                    msg.Body    = "Dear " + usr.FirstName + ",<br>" +
                                  "this is just a notification email to inform you that you fired a worker " + reason + "." +
                                  "<br><br>Best regards,<br>Aleksandar Matic";
                }
                //korisnik je poslao zahtjev za posao, mail ide kompaniji
                if (type == 3)
                {
                    msg.Subject = "You have a job application, " + usr.FirstName + "!";
                    msg.Body    = "Dear " + usr.FirstName + ",<br>" +
                                  "it seems someone requested a working spot in your company. Please, log in to review the request." +
                                  "<br><br>Best regards,<br>Aleksandar Matic";
                }

                client.Send(msg);
            }
        }
Exemplo n.º 12
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.º 13
0
        public JsonResult AllTechs(int pathId)
        {
            List <TechnologyVM> lista = new List <TechnologyVM>();

            using (ITExpertsContext db = new ITExpertsContext())
            {
                lista = db.Technologies.ToArray()
                        .Where(x => x.PathId == pathId)
                        .Select(x => new TechnologyVM(x)).ToList();
            }

            return(Json(lista, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 14
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.º 15
0
        private void SendMail(string mail, int type, string reason)
        {
            MailAddress sender   = new MailAddress("*****@*****.**", "Lead administrator from ITExperts.com");
            MailAddress receiver = new MailAddress(mail);
            MailMessage msg      = new MailMessage(sender, receiver);

            msg.From = sender;
            msg.To.Add(receiver);
            msg.IsBodyHtml = true;
            NetworkCredential credentials = new NetworkCredential("*****@*****.**", "utbnwuvztkbgwpwj", "");
            SmtpClient        client      = new SmtpClient("smtp.gmail.com", 587);

            client.EnableSsl   = true;
            client.Credentials = credentials;

            User usr = null;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                usr = db.Users.Single(x => x.Email.Equals(mail));
            }

            if (usr != null)
            {
                if (usr.MadeUp != true)
                {
                    //admin obrisao moda, salje se modu
                    if (type == 1)
                    {
                        msg.Subject = "Your account has been permanently deleted!";
                        msg.Body    = "Dear " + usr.FirstName + " " + usr.LastName + ",<br>" +
                                      "your account has been permanently deleted! <br><br>Reason:<br>" +
                                      reason + "<br><br>If you decide to apeal, do so in a form of reply to this mail." +
                                      "<br><br>Kind regards,<br>Aleksandar Matic";
                    }
                    //admin blokirao moda, salje se modu
                    else if (type == 2)
                    {
                        msg.Subject = "Your account has been blocked by administrator!";
                        msg.Body    = "Dear " + usr.FirstName + " " + usr.LastName + ",<br>" +
                                      "your account has been blocked! If you decide to apeal, do so in a form of " +
                                      "reply to this mail.<br><br>Kind regards,<br>Aleksandar Matic";
                    }

                    client.Send(msg);
                }
            }
        }
Exemplo n.º 16
0
        public JsonResult SingleUserForRespond(int id)
        {
            UserVM user = new UserVM();

            using (ITExpertsContext db = new ITExpertsContext())
            {
                user = new UserVM(db.Users.Find(id));
            }

            if (user != null)
            {
                return(Json(user, JsonRequestBehavior.AllowGet));
            }

            return(null);
        }
        public JsonResult AllCompanies()
        {
            List <CompanyVM> lista = new List <CompanyVM>();

            using (ITExpertsContext db = new ITExpertsContext())
            {
                foreach (Company c in db.Companies)
                {
                    if (c.Active == true && c.Blocked == false)
                    {
                        lista.Add(new CompanyVM(c));
                    }
                }
            }

            return(Json(lista, JsonRequestBehavior.AllowGet));
        }
        public JsonResult CheckIfEmployed(int UserId)
        {
            string CompanyMail = User.Identity.Name;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                Company cmp = db.Companies.First(x => x.Email.Equals(CompanyMail));

                if (db.WorkingAts.Any(x => x.UserId == UserId && x.CompanyId == cmp.CompanyId && x.Until == null))
                {
                    return(Json("1", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult AllEmployees()
        {
            string mail = User.Identity.Name;

            Company cmp = null;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                cmp = db.Companies.Single(x => x.Email.Equals(mail));
            }

            if (cmp != null)
            {
                return(View(cmp.CompanyId));
            }

            return(View(0));
        }
Exemplo n.º 20
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.º 21
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.º 22
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.º 23
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.º 24
0
        public WorkingAtVM(WorkingAt job)
        {
            ITExpertsContext db = new ITExpertsContext();

            JobId       = job.JobId;
            CompanyId   = job.CompanyId;
            CompanyName = job.CompanyName;
            Description = job.Description;
            PathId      = job.Tech.PathId;
            Since       = job.Since;
            Until       = job.Until;
            UserId      = job.UserId;
            WorkingAt[] listToConvert = db.WorkingAts.ToList().Where(x => x.UserId == UserId && x.CompanyName == CompanyName && x.Since == Since).OrderBy(x => x.TechId).ToArray();
            TechId = new int[listToConvert.Count()];
            for (int i = 0; i < listToConvert.Count(); i++)
            {
                TechId[i] = listToConvert[i].TechId;
            }
            db.Dispose();
        }
        public JsonResult Employees()
        {
            string mail = User.Identity.Name;

            List <UserVM> list = null;

            using (ITExpertsContext db = new ITExpertsContext())
            {
                Company    cmp = db.Companies.Single(x => x.Email == mail);
                List <int> ids = db.WorkingAts.Where(x => x.CompanyId == cmp.CompanyId && x.Until == null).Select(x => x.UserId).Distinct().ToList();

                list = db.Users.Where(x => ids.Contains(x.UserId)).ToList().Select(x => new UserVM(x)).ToList();
            }

            foreach (UserVM user in list)
            {
                user.Salary = Math.Round(user.Salary, 2);
            }

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 26
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.º 27
0
        public static WorkingAtVM[] ReturnJobs(int id)
        {
            using (ITExpertsContext db = new ITExpertsContext())
            {
                WorkingAt[]   listToConvert = db.WorkingAts.ToList().Where(x => x.UserId == id).ToArray();
                WorkingAtVM[] list          = null;

                if (listToConvert.Count() > 0)
                {
                    int numberOfJobs = 1;
                    for (int i = 1; i < listToConvert.Count(); i++)
                    {
                        if (listToConvert[i].CompanyName != listToConvert[i - 1].CompanyName &&
                            listToConvert[i].Since != listToConvert[i - 1].Since)
                        {
                            numberOfJobs++;
                        }
                    }

                    list = new WorkingAtVM[numberOfJobs];

                    list[0] = new WorkingAtVM(listToConvert[0]);
                    int j = 1;

                    for (int i = 1; i < listToConvert.Count(); i++)
                    {
                        if (listToConvert[i].CompanyName != listToConvert[i - 1].CompanyName &&
                            listToConvert[i].Since != listToConvert[i - 1].Since)
                        {
                            list[j] = new WorkingAtVM(listToConvert[i]);
                            j++;
                        }
                    }
                }

                return(list);
            }
        }
        public ActionResult PublicCompanyProfile(int id)
        {
            if (id < 100)
            {
                return(HttpNotFound());
            }

            CompanyVM model = null;

            try
            {
                using (ITExpertsContext db = new ITExpertsContext())
                {
                    model           = new CompanyVM(db.Companies.Where(x => x.Active == true && x.Blocked == false).ToList().First(x => x.CompanyId == id));
                    model.Employees = db.WorkingAts.Where(x => x.Until == null && x.CompanyId == id && x.User.Blocked == false && x.User.Active == true).Select(x => x.UserId).Distinct().Count();
                }
            }
            catch (Exception)
            {
            }

            return(View(model));
        }
Exemplo n.º 29
0
        public JsonResult ReturnTech(int techId)
        {
            if (techId != 0)
            {
                using (ITExpertsContext db = new ITExpertsContext())
                {
                    Technology   row   = db.Technologies.Find(techId);
                    TechnologyVM model = new TechnologyVM()
                    {
                        TechId          = row.TechId,
                        TechName        = row.TechName,
                        TechDescription = row.TechDescription,
                        PathId          = row.PathId
                    };

                    return(Json(model, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 30
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);
                }
            }
        }