Пример #1
0
        /// <summary>
        /// This method returns Json string with add procedure result
        /// </summary>
        /// <param name="command1"></param>
        /// <param name="command2"></param>
        /// <returns></returns>
        public string AddUser(string command1, string command2)
        {
            string serialized1, serialized2;

            try
            {
                db.Users.Add(new User {
                    NickName = command1, FullName = command2
                });
                db.SaveChanges();
                string answer1 = "Operation successful!";
                serialized1 = JsonConvert.SerializeObject(answer1);
            }
            catch (Exception ex)
            {
                string answer2 = "Operation failed!" + ex.Message;
                serialized2 = JsonConvert.SerializeObject(answer2);
                return(serialized2);
            }
            return(serialized1);
        }
Пример #2
0
        /// <summary>
        /// This method returns Json string with delete procedure result
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public string DelUser(string command)
        {
            DBRest db = new DBRest();
            string serialized1, serialized2;

            try
            {
                var deleted = db.Users.Where(p => p.NickName == command).FirstOrDefault();
                db.Users.Remove(deleted);
                db.SaveChanges();
                string answer1 = "Operation successful!";
                serialized1 = JsonConvert.SerializeObject(answer1);
            }
            catch (Exception ex)
            {
                string answer2 = "Operation failed!" + ex.Message;
                serialized2 = JsonConvert.SerializeObject(answer2);
                return(serialized2);
            }
            return(serialized1);
        }