public static List <DimAccount> GetAccounts(string connectionString, string sidx, string sort, int page, int rows, out int totalRecords)
        {
            sort = (sort == null) ? "" : sort;
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize  = rows;

            AdventureworksDW2016CTP3Entities entities = new AdventureworksDW2016CTP3Entities(connectionString);

            totalRecords = entities.DimAccounts.Count();

            if (sort.ToUpper() == "DESC")
            {
                if (string.IsNullOrEmpty(sidx))
                {
                    return(entities.DimAccounts.OrderByDescending(x => x.AccountDescription).Skip(pageIndex * pageSize).Take(pageSize).ToList());
                }
                return(entities.DimAccounts.OrderByDescending(sidx).Skip(pageIndex * pageSize).Take(pageSize).ToList());
            }
            else
            {
                if (string.IsNullOrEmpty(sidx))
                {
                    return(entities.DimAccounts.OrderBy(x => x.AccountDescription).Skip(pageIndex * pageSize).Take(pageSize).ToList());
                }
                return(entities.DimAccounts.OrderBy(sidx).Skip(pageIndex * pageSize).Take(pageSize).ToList());
            }
        }
        public static string UpdateAccount(string connectionString, int id, DimAccount model)
        {
            using (AdventureworksDW2016CTP3Entities db = new AdventureworksDW2016CTP3Entities(connectionString))
            {
                string msg;
                try
                {
                    var account = db.DimAccounts.SingleOrDefault(x => x.AccountKey == id);

                    if (account != null)
                    {
                        account.AccountDescription = model.AccountDescription;
                        account.AccountType        = model.AccountType;
                        db.SaveChanges();
                        msg = "Saved Successfully";
                    }
                    else
                    {
                        msg = "Unique record not found on server";
                    }
                }
                catch (DbUpdateException ex)
                {
                    bool isPrimary = IsPrimaryDatabase(connectionString);
                    if (!isPrimary)
                    {
                        msg = "Can not add or modify the records as secondary database is readonly.";
                    }
                    else
                    {
                        msg = "Error occured:" + ex.Message;
                    }
                }
                catch (Exception ex)
                {
                    msg = "Error occured:" + ex.Message;
                }
                return(msg);
            }
        }