示例#1
0
        public ContentResult Apply(FormCollection form)
        {
            JObject json = new JObject();

            json["error"]   = false;
            json["message"] = "";

            string[] keys = new string[] { "id" };

            if (this.HasValues(form, keys))
            {
                if (this.IsLoggedIn() && this.GetAccount().Type == AccountType.Applicant)
                {
                    DBHandler db = new DBHandler();

                    try
                    {
                        JobPosting     job         = new JobPosting(Int32.Parse(form.GetValue("id").AttemptedValue));
                        JobApplication application = new JobApplication();
                        application.JobPosting = job;
                        application.Status     = JobApplicationStatus.Undecided;
                        application.Applicant  = ((Applicant)this.GetAccount().Profile);

                        application.Create();
                        json["message"] = "You have applied for: " + job.JobTitle
                                          + "; please wait for the HR to contact you";
                        using (DataTable dt = db.Execute <DataTable>(
                                   CRUD.READ,
                                   "SELECT E.Profile FROM Employee E INNER JOIN Department D ON E.Department = D.DepartmentID WHERE D.Type = "
                                   + ((int)DepartmentType.HumanResources)))
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                Notification notifHR = new Notification();
                                notifHR.Account   = new Account().FindByProfile(Int32.Parse(row["Profile"].ToString()));
                                notifHR.TimeStamp = DateTime.Now;
                                notifHR.Status    = NotificationStatus.Unread;
                                notifHR.Message   = "An applicant has applied for the job: <b>" + job.JobTitle + "</b>";

                                notifHR.Create();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        json["error"]   = true;
                        json["message"] = e.Message;
                    }
                }
                else
                {
                    json["error"]   = true;
                    json["message"] = "You are not authorized to continue";
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "Form is incomplete";
            }

            return(Content(json.ToString(), "application/json"));
        }