Ejemplo n.º 1
0
    public static ReturnObject EditHoliday(string current, string previous)
    {
        masters_holiday page_object           = new masters_holiday();
        DBConnection    db_connection         = new DBConnection();
        ReturnObject    return_object         = new ReturnObject();
        string          query                 = string.Empty;
        string          holiday_code          = string.Empty;
        string          holiday_name          = string.Empty;
        string          holiday_from          = string.Empty;
        string          holiday_to            = string.Empty;
        string          company_code          = string.Empty;
        string          holiday_type          = string.Empty;
        string          original_holiday_name = string.Empty;
        string          original_holiday_from = string.Empty;
        string          original_holiday_to   = string.Empty;
        int             count                 = 0;

        if (HttpContext.Current.Session["username"] == null)  // checking session expired or not
        {
            return_object = page_object.DoLogout();
        }
        else
        {
            try
            {
                JObject current_data  = JObject.Parse(current);
                JObject original_data = JObject.Parse(previous);

                holiday_code = current_data["holiday_code"].ToString();
                holiday_name = current_data["holiday_name"].ToString();
                holiday_from = current_data["holiday_from"].ToString();
                holiday_to   = current_data["holiday_to"].ToString();
                company_code = current_data["company_code"].ToString();
                holiday_type = current_data["holiday_type"].ToString();

                original_holiday_name = original_data["holiday_name"].ToString();
                original_holiday_from = original_data["holiday_from"].ToString();
                original_holiday_to   = original_data["holiday_to"].ToString();

                if (original_holiday_name != holiday_name)
                {
                    count = page_object.CheckHolidayName(holiday_name, company_code);
                    if (count > 0)
                    {
                        return_object.status      = "error";
                        return_object.return_data = "A Holiday with the same Name has been created. Please try again with a different Holiday Name.";

                        return(return_object);
                    }
                }
                Debug.Write(original_holiday_from + " " + holiday_from);
                if (original_holiday_from != holiday_from || original_holiday_to != holiday_to)
                {
                    count = page_object.CheckHolidayDates(holiday_from, holiday_to);
                    if (count > 0)
                    {
                        return_object.status      = "error";
                        return_object.return_data = "The selected From and To Dates have been mapped to another Holiday. Please try again with different Dates";

                        return(return_object);
                    }
                }

                page_object.UpdateDatabase(holiday_code, holiday_name, holiday_from, holiday_to, company_code, "0", holiday_code, "U", holiday_type);

                return_object.status      = "success";
                return_object.return_data = "Holiday edited successfully!";
            }
            catch (Exception Ex)
            {
                Logger.LogException(Ex, page, "EDIT_HOLIDAY");

                return_object.status      = "error";
                return_object.return_data = "An error occurred while performing this operation. Please try again. If the error persists, please contact Support";

                throw;
            }
            finally
            {
                page_object.Dispose();
            }
        }
        return(return_object);
    }
Ejemplo n.º 2
0
    public static ReturnObject AddHoliday(string current)
    {
        masters_holiday page_object   = new masters_holiday();
        DBConnection    db_connection = new DBConnection();
        ReturnObject    return_object = new ReturnObject();

        int count = 0;

        string
            query        = string.Empty,
            holiday_code = string.Empty,
            holiday_name = string.Empty,
            holiday_from = string.Empty,
            holiday_to   = string.Empty,
            company_code = string.Empty,
            holiday_type = string.Empty;

        try
        {
            JObject current_data = JObject.Parse(current);
            holiday_code = current_data["holiday_code"].ToString();
            holiday_name = current_data["holiday_name"].ToString();
            holiday_from = current_data["holiday_from"].ToString();
            holiday_to   = current_data["holiday_to"].ToString();
            company_code = current_data["company_code"].ToString();
            holiday_type = current_data["holiday_type"].ToString();


            count = page_object.CheckHolidayCode(holiday_code, company_code);
            if (count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "A Holiday with the same Code has been created. Please try again with a different Holiday Code.";

                return(return_object);
            }

            count = page_object.CheckHolidayName(holiday_name, company_code);
            if (count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "A Holiday with the same Name has been created. Please try again with a different Holiday Name.";

                return(return_object);
            }

            count = page_object.CheckHolidayDates(holiday_from, holiday_to, company_code);
            if (count > 0)
            {
                return_object.status      = "error";
                return_object.return_data = "The selected From and To Dates have been mapped to another holiday. Please try again with different dates.";

                return(return_object);
            }

            page_object.UpdateDatabase(holiday_code, holiday_name, holiday_from, holiday_to, company_code, "0", "hol", "I", holiday_type);

            return_object.status      = "success";
            return_object.return_data = "Holiday added successfully!";
        }
        catch (Exception Ex)
        {
            Logger.LogException(Ex, page, "ADD_HOLIDAY");

            return_object.status      = "error";
            return_object.return_data = "An error occurred while performing this operation. Please try again. If the error persists, please contact Support.";

            throw;
        }
        finally
        {
            page_object.Dispose();
        }

        return(return_object);
    }