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 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")); }
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(); }