Ejemplo n.º 1
0
        // GET: Reports/AllTrainings
        public ContentResult AllTraining()
        {
            JObject json = new JObject();

            json["content"] = null;
            List <AssignedTraining> AssignedTrainings = new List <AssignedTraining>();

            DBHandler db = new DBHandler();

            using (DataTable dt = db.Execute <DataTable>(
                       CRUD.READ,
                       "SELECT AssignedTrainingID, Status, TrainingHistoryID, Profile FROM AssignedTraining AT"
                       + " INNER JOIN TrainingHistory T ON AT.Training = T.TrainingHistoryID "
                       + " ORDER BY AT.Profile DESC, T.StartDate DESC"))
            {
                foreach (DataRow row in dt.Rows)
                {
                    AssignedTraining at = new AssignedTraining();
                    at.Status = (TrainingStatus)Int32.Parse(row["Status"].ToString());

                    at.Profile  = new Profile(Int32.Parse(row["Profile"].ToString()));
                    at.Training = new Training(Int32.Parse(row["TrainingHistoryID"].ToString()));

                    AssignedTrainings.Add(at);
                }
            }

            if (AssignedTrainings.Count > 0)
            {
                json["content"] = JArray.FromObject(AssignedTrainings);
            }

            return(Content(json.ToString(), "application/json"));
        }
Ejemplo n.º 2
0
        public ContentResult UpdateAssigned(FormCollection form)
        {
            JObject json = new JObject();

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

            if (!this.CheckLogin(AccountType.Applicant) && ((Employee)this.GetAccount().Profile).Department.Type
                == DepartmentType.HumanResources)
            {
                if (form.GetValue("v") != null && Int32.Parse(form.GetValue("v").AttemptedValue) <= 2 || Int32.Parse(form.GetValue("v").AttemptedValue) >= 1)
                {
                    AssignedTraining at = new AssignedTraining(Int32.Parse(form.GetValue("id").AttemptedValue));
                    at.Status = (TrainingStatus)Int32.Parse(form.GetValue("v").AttemptedValue);
                    at.Update(false);
                }
                else
                {
                    json["error"]   = true;
                    json["message"] = "Form is incomplete";
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "You are not authorized to continue";
            }

            return(Content(json.ToString(), "application/json"));
        }
Ejemplo n.º 3
0
        public ContentResult Assign(FormCollection form)
        {
            JObject json = new JObject();

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

            if (!this.CheckLogin(AccountType.Applicant) && this.GetAccount().Type == AccountType.DepartmentHead)
            {
                if (form.GetValue("profile") != null && form.GetValue("training") != null)
                {
                    try
                    {
                        Profile  Profile  = new Profile(Int32.Parse(form.GetValue("profile").AttemptedValue));
                        Training Training = new Training(Int32.Parse(form.GetValue("training").AttemptedValue));

                        AssignedTraining at = new AssignedTraining();
                        at.Profile  = Profile;
                        at.Training = Training;

                        if (form.GetValue("suggested") == null)
                        {
                            at.Status = TrainingStatus.Pending;
                        }
                        else
                        {
                            at.Status = TrainingStatus.Suggested;
                        }

                        at.Create(false);

                        Notification notif = new Notification();
                        notif.Account = new Account().FindByProfile(at.Profile.ProfileID);

                        if (at.Status == TrainingStatus.Pending)
                        {
                            notif.Message =
                                "You've been assigned to a Training service, please check the Assigned Trainings page.";
                            json["message"] = "Succesfully assigned employee to training service...";
                        }
                        else
                        {
                            notif.Message =
                                "You were suggested to join a Training service, please wait for further instructions.";
                            json["message"] = "Succesfully suggested employee to training service...";
                        }

                        notif.Status    = NotificationStatus.Unread;
                        notif.TimeStamp = DateTime.Now;

                        notif.Create();

                        DBHandler db = new DBHandler();
                        using (DataTable dt = db.Execute <DataTable>(
                                   CRUD.READ,
                                   "SELECT Profile FROM Employee E INNER JOIN Department D ON E.Department = D.DepartmentID WHERE Type = "
                                   + ((int)DepartmentType.HumanResources)))
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                Account      a = new Account().FindByProfile(Int32.Parse(row["Profile"].ToString()), false);
                                Notification n = new Notification();
                                n.Status    = NotificationStatus.Unread;
                                n.TimeStamp = DateTime.Now;
                                n.Account   = a;
                                n.Message   = "An employee was suggested for training";

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

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