public JsonResult MR_Edit(MugsModalModel jsonString)
        {
            string MugKey         = jsonString.MugKey;
            string MugID          = jsonString.MugID;
            bool   CurrentlyInUse = jsonString.CurrentlyInUse;
            string Notes          = jsonString.Notes;

            //Notes field is allowed to be null, therfore account for string variation
            if (Notes != null)
            {
                Notes = "'" + Notes + "'";
            }
            else
            {
                Notes = "NULL";
            }

            bool          editStatus = mugregistry.EditQuery(MugKey, MugID, CurrentlyInUse, Notes);
            IsTrueOrFalse model      = new IsTrueOrFalse(editStatus);

            return(ResultJson(model));
        }
Exemple #2
0
        /*
         *  Function: GetRecord
         *
         *  Get data for mug registry modals.
         *
         *  Returns:
         *
         *      model - a MugsModalModel model of the record with the primary key equal to the MugKey
         */
        public static MugsModalModel GetRecord(string MugKey)
        {
            SqlConnection  dbconnection = new SqlConnection();
            SqlCommand     dbcommand    = new SqlCommand();
            SqlDataReader  dbreader;
            string         connectionstring = ConfigurationManager.ConnectionStrings["MugShareDB"].ToString();
            string         queryString      = "SELECT * FROM MugRegistry WHERE pKey = " + MugKey;
            MugsModalModel model            = new MugsModalModel();

            try
            {
                if (dbconnection.State == ConnectionState.Closed)
                {
                    dbconnection.ConnectionString = connectionstring; dbconnection.Open();
                }
                dbcommand.Connection     = dbconnection;
                dbcommand.CommandTimeout = 600;
                dbcommand.CommandText    = queryString;
                dbcommand.CommandType    = CommandType.Text;
                dbreader = dbcommand.ExecuteReader();
                if (dbreader.HasRows)
                {
                    dbreader.Read();
                    if (!string.IsNullOrEmpty(dbreader["pKey"].ToString()))
                    {
                        model.MugKey = dbreader["pKey"].ToString();
                    }
                    if (!string.IsNullOrEmpty(dbreader["MugID"].ToString()))
                    {
                        model.MugID = dbreader["MugID"].ToString();
                    }
                    if (!string.IsNullOrEmpty(dbreader["LastBorrowedBy"].ToString()))
                    {
                        model.LastBorrowedBy = dbreader["LastBorrowedBy"].ToString();
                    }

                    if (dbreader["CurrentlyInUse"].ToString() == "True")
                    {
                        model.CurrentlyInUse = true;
                    }
                    else
                    {
                        model.CurrentlyInUse = false;
                    }

                    if (!string.IsNullOrEmpty(dbreader["Notes"].ToString()))
                    {
                        model.Notes = dbreader["Notes"].ToString();
                    }
                }
                return(model);
            }
            catch (Exception e)
            {
                throw new Exception(@"Mug-Share Application GetRecord() failed : ", e);
            }
            finally
            {
                if (dbconnection.State == ConnectionState.Open)
                {
                    dbconnection.Close();
                }
            }
        }
        public JsonResult MR_GetRecord(string MugKey)
        {
            MugsModalModel model = mugregistry.GetRecord(MugKey);

            return(ResultJson(model));
        }