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"));
                }
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public ActionResult PublicProfile(int id)
        {
            if (id < 100)
            {
                return(HttpNotFound());
            }

            UserVM model = null;

            try
            {
                using (ITExpertsContext db = new ITExpertsContext())
                {
                    model = new UserVM(db.Users.Find(id));

                    List <WorkingAt> jobs = db.WorkingAts.Where(x => x.UserId == id).ToList();

                    int index = 0;

                    if (jobs.Count() != 0)
                    {
                        model.Jobs = new WorkingAtVM[db.WorkingAts.Where(x => x.UserId == model.UserId).GroupBy(x => new { x.CompanyName, x.Since }).Select(x => x).Count()];

                        int i = 0;
                        while (i < jobs.Count)
                        {
                            WorkingAtVM job = new WorkingAtVM();

                            job.CompanyId   = jobs[i].CompanyId;
                            job.CompanyName = jobs[i].CompanyName;
                            job.Description = jobs[i].Description;
                            job.JobId       = jobs[i].JobId;
                            job.PathId      = jobs[i].Tech.PathId;
                            job.Since       = jobs[i].Since;
                            job.Until       = jobs[i].Until;
                            job.UserId      = id;
                            job.TechId      = new int[db.WorkingAts.Count(x => x.UserId == id && x.CompanyId == job.CompanyId && x.Since == job.Since)];
                            job.Technology  = new string[db.WorkingAts.Count(x => x.UserId == id && x.CompanyId == job.CompanyId && x.Since == job.Since)];
                            int j = 0;
                            while (j < job.TechId.Count())
                            {
                                job.TechId[j] = jobs[i].TechId;
                                Technology bla = db.Technologies.Find(jobs[i].TechId);
                                job.Technology[j] = bla.TechName;
                                i++;
                                j++;
                            }
                            model.Jobs[index] = job;
                            index++;
                        }
                    }

                    model.Salary = HelpClass.ReturnSalary(model.UserId);
                }
            }
            catch (Exception)
            {
            }

            if (model != null)
            {
                return(View(model));
            }

            return(HttpNotFound());
        }