Пример #1
0
 /// <summary>
 /// Called from PUT
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="returnMessage"></param>
 /// <returns></returns>
 public bool Update(categories obj, out string returnMessage)
 {
     returnMessage = string.Empty;
     using (var edc = new EDC())
     {
         edc.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         try
         {
             edc.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             returnMessage = ex.Message;
             return(false);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Called from DELETE
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="returnMessage"></param>
        /// <returns></returns>
        public bool Delete(string id, out string returnMessage)
        {
            returnMessage = string.Empty;
            using (var edc = new EDC())
            {
                categories obj = Get(id);

                edc.Entry(obj).State = System.Data.Entity.EntityState.Deleted;
                try
                {
                    edc.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    returnMessage = ex.Message;
                    return(false);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Called from POST
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="returnMessage"></param>
        /// <returns></returns>
        public bool Create(categories obj, out string returnMessage)
        {
            Guid id = Guid.NewGuid();

            obj.id        = id.ToString();
            returnMessage = id.ToString();
            using (var edc = new EDC())
            {
                edc.Categories.Add(obj);
                try
                {
                    edc.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    returnMessage = ex.Message;
                    return(false);
                }
            }
        }