Beispiel #1
0
    public static ReturnObject DeleteHoliday(string current)
    {
        masters_holiday page_object   = new masters_holiday();
        DBConnection    db_connection = new DBConnection();
        ReturnObject    return_object = new ReturnObject();
        string          query         = string.Empty;
        int             count         = 0;

        string
            company_code       = string.Empty,
            holiday_group_code = string.Empty,
            holiday_code       = string.Empty,
            holiday_from       = string.Empty,
            holiday_to         = string.Empty,
            holiday_type       = string.Empty;

        if (HttpContext.Current.Session["username"] == null)  // checking session expired or not
        {
            return_object = page_object.DoLogout();
        }
        else
        {
            try
            {
                JObject current_data = JObject.Parse(current);
                holiday_code = current_data["holiday_code"].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();

                query = "select count(*) from HolidayListDetails where holcode in(select distinct holcode from HolidayMaster where holcode = '" + holiday_code + "')";
                count = db_connection.GetRecordCount(query);
                if (count > 0)
                {
                    return_object.status      = "error";
                    return_object.return_data = "Holidays have been mapped to Holiday Group List. Please unassign the holidays from the Holiday Group List and try again.";
                }
                else
                {
                    page_object.UpdateDatabase(holiday_code, null, holiday_from, holiday_to, company_code, "0", holiday_code, "D", holiday_type);

                    return_object.status      = "success";
                    return_object.return_data = "Holiday deleted successfully!";
                }
            }
            catch (Exception Ex)
            {
                Logger.LogException(Ex, page, "DELETE_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);
    }
Beispiel #2
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);
    }