예제 #1
0
        public IHttpActionResult postAction(SpoolerViewModel model)
        {
            db.openConnection();
            DataTable dt           = null;
            var       objFunctions = new Commons.functions();

            try
            {
                if (model.actionUser.ToLower() == "add_spooler_draw_warning" || model.actionUser.ToLower() == "add_spooler_draw_done")
                {
                    paramName  = new string[] { "pIdCamp", "pDescription", "pTypeSpooler", "pIdUsuResponsible" };
                    paramValue = new string[] { Convert.ToString(model.championshipID), model.descriptionProcess, model.typeProcess, model.userIDResponsible.ToString() };
                    dt         = db.executePROC("spAddSpoolerDraw", paramName, paramValue);

                    if (dt.Rows.Count > 0)
                    {
                        model.totalSentEmails = Convert.ToInt32(dt.Rows[0]["TOTAL_EMAILS_SENT"].ToString());
                    }

                    model.returnMessage = "ModeratorSuccessfully";
                    return(CreatedAtRoute("DefaultApi", new { id = 0 }, model));
                }
                else
                {
                    return(StatusCode(HttpStatusCode.NotAcceptable));
                }
            }
            catch (Exception ex)
            {
                model.returnMessage = "errorPostSpooler_" + ex.Message;
                return(CreatedAtRoute("DefaultApi", new { id = 0 }, model));
            }
            finally
            {
                db.closeConnection();
                dt           = null;
                objFunctions = null;
            }
        }
        public IHttpActionResult ranking(SummaryViewModel model)
        {
            DataTable dt = null;

            try
            {
                if (model.actionUser == "summary")
                {
                    db.openConnection();
                    try
                    {
                        paramName  = new string[] { };
                        paramValue = new string[] { };
                        dt         = db.executePROC("spGetSummaryModeratorMenu", paramName, paramValue);

                        model.totalActiveCoaches  = Convert.ToInt16(dt.Rows[0]["totalActiveCoaches"].ToString());
                        model.totalSeasonCoaches  = Convert.ToInt16(dt.Rows[0]["totalSeasonCoaches"].ToString());
                        model.currentStageNameH2H = dt.Rows[0]["currentStageNameH2H"].ToString();

                        model.seasonNameH2H = dt.Rows[0]["seasonNameH2H"].ToString();
                        model.seasonNameFUT = dt.Rows[0]["seasonNameFUT"].ToString();
                        model.seasonNamePRO = dt.Rows[0]["seasonNamePRO"].ToString();

                        model.returnMessage = "ModeratorSuccessfully";
                        return(CreatedAtRoute("DefaultApi", new { id = 0 }, model));
                    }
                    catch (Exception ex)
                    {
                        model = new SummaryViewModel();
                        model.returnMessage = "error_" + ex.Message;
                        return(CreatedAtRoute("DefaultApi", new { id = 0 }, model));
                    }
                    finally
                    {
                    }
                }
                else if (model.actionUser == "spooler")
                {
                    db.openConnection("Connection.Database.Spooler");
                    SpoolerViewModel        SpoolerViewModel = new SpoolerViewModel();
                    List <SpoolerTypeModel> listProcessing   = new List <SpoolerTypeModel>();
                    List <SpoolerTypeModel> listWaiting      = new List <SpoolerTypeModel>();
                    List <SpoolerTypeModel> listFinished     = new List <SpoolerTypeModel>();
                    List <SpoolerTypeModel> listAdmin        = new List <SpoolerTypeModel>();

                    try
                    {
                        int    currentTime     = DateTime.Now.Hour;
                        int    currentDay      = DateTime.Now.Day;
                        int    currentMonth    = DateTime.Now.Month;
                        int    currentYear     = DateTime.Now.Year;
                        string nextProcessTime = String.Empty;

                        if (currentTime >= 22 && currentTime <= 23)
                        {
                            currentDay      = DateTime.Now.AddDays(1).Day;
                            currentMonth    = DateTime.Now.AddDays(1).Month;
                            currentYear     = DateTime.Now.AddDays(1).Year;
                            nextProcessTime = "04:00";
                        }
                        else if (currentTime >= 0 && currentTime < 4)
                        {
                            nextProcessTime = "04:00";
                        }
                        else if (currentTime >= 4 && currentTime < 6)
                        {
                            nextProcessTime = "06:00";
                        }
                        else if (currentTime >= 6 && currentTime < 8)
                        {
                            nextProcessTime = "08:00";
                        }
                        else if (currentTime >= 8 && currentTime < 10)
                        {
                            nextProcessTime = "10:00";
                        }
                        else if (currentTime >= 10 && currentTime < 12)
                        {
                            nextProcessTime = "12:00";
                        }
                        else if (currentTime >= 12 && currentTime < 14)
                        {
                            nextProcessTime = "14:00";
                        }
                        else if (currentTime >= 14 && currentTime < 16)
                        {
                            nextProcessTime = "16:00";
                        }
                        else if (currentTime >= 16 && currentTime < 18)
                        {
                            nextProcessTime = "18:00";
                        }
                        else if (currentTime >= 18 && currentTime < 20)
                        {
                            nextProcessTime = "20:00";
                        }
                        else if (currentTime >= 20 && currentTime < 22)
                        {
                            nextProcessTime = "22:00";
                        }


                        SpoolerViewModel.nextTimeProcessSpooler = currentDay.ToString("00") + "/" +
                                                                  currentMonth.ToString("00") + "/" +
                                                                  currentYear.ToString("0000") + " " +
                                                                  nextProcessTime + "h";


                        paramName      = new string[] { };
                        paramValue     = new string[] { };
                        dt             = db.executePROC("spGetAllSpoolerInProgress", paramName, paramValue);
                        listProcessing = subSetUpListReturnSpooler(dt);


                        dt          = db.executePROC("spGetAllSpoolerWaitingProcess", paramName, paramValue);
                        listWaiting = subSetUpListReturnSpooler(dt);

                        dt           = db.executePROC("spGetAllSpoolerFinished", paramName, paramValue);
                        listFinished = subSetUpListReturnSpooler(dt);

                        dt        = db.executePROC("spGetAllSpoolerAdmin", paramName, paramValue);
                        listAdmin = subSetUpListReturnSpooler(dt);

                        SpoolerViewModel.listSpoolerInProgress = listProcessing;
                        SpoolerViewModel.listSpoolerWaiting    = listWaiting;
                        SpoolerViewModel.listSpoolerFinished   = listFinished;
                        SpoolerViewModel.listSpoolerAdmin      = listAdmin;
                        SpoolerViewModel.returnMessage         = "ModeratorSuccessfully";
                        return(CreatedAtRoute("DefaultApi", new { id = 0 }, SpoolerViewModel));
                    }
                    catch (Exception ex)
                    {
                        SpoolerViewModel = new SpoolerViewModel();
                        SpoolerViewModel.listSpoolerInProgress = new List <SpoolerTypeModel>();
                        SpoolerViewModel.listSpoolerWaiting    = new List <SpoolerTypeModel>();
                        SpoolerViewModel.listSpoolerFinished   = new List <SpoolerTypeModel>();
                        SpoolerViewModel.listSpoolerAdmin      = new List <SpoolerTypeModel>();
                        SpoolerViewModel.returnMessage         = "error_" + ex.Message;
                        return(CreatedAtRoute("DefaultApi", new { id = 0 }, SpoolerViewModel));
                    }
                    finally
                    {
                        SpoolerViewModel = null;
                        listProcessing   = null;
                        listWaiting      = null;
                        listFinished     = null;
                        listAdmin        = null;
                    }
                }
                else
                {
                    return(StatusCode(HttpStatusCode.NotAcceptable));
                }
            }
            catch (Exception ex)
            {
                model = new SummaryViewModel();
                model.returnMessage = "error_" + ex.Message;
                return(CreatedAtRoute("DefaultApi", new { id = 0 }, model));
            }
            finally
            {
                db.closeConnection();
                dt = null;
            }
        }