示例#1
0
 /// <summary>
 /// Get single clothe from the database by Id
 /// </summary>
 public Clothe Get(int id)
 {
     using (clotheContext = new ClotheContext())
     {
         return(clotheContext.Clothes.Find(id));
     }
 }
示例#2
0
 /// <summary>
 /// Get all clothes from the database
 /// </summary>
 public List <Clothe> GetAll()
 {
     using (clotheContext = new ClotheContext())
     {
         return(clotheContext.Clothes.ToList());
     }
 }
示例#3
0
        /// <summary>
        /// Add a product to the database
        /// </summary>
        public string Add(Clothe clothe)
        {
            using (clotheContext = new ClotheContext())
            {
                clotheContext.Clothes.Add(clothe);

                clotheContext.SaveChanges();
            }

            return("The element is added");
        }
示例#4
0
 /// <summary>
 /// Update a single clothe in the database by Id.
 /// </summary>
 public void Update(Clothe clothe)
 {
     using (clotheContext = new ClotheContext())
     {
         var item = clotheContext.Clothes.Find(clothe.Id);
         if (item != null)
         {
             clotheContext.Entry(item).CurrentValues.SetValues(clothe);
             clotheContext.SaveChanges();
         }
     }
 }
示例#5
0
        /// <summary>
        /// Deleate a clothe from the database by Id
        /// </summary>
        public string Delete(int id)
        {
            using (clotheContext = new ClotheContext())
            {
                var product = clotheContext.Clothes.Find(id);
                if (product != null)
                {
                    clotheContext.Clothes.Remove(product);
                    clotheContext.SaveChanges();
                    return("Clothe was deleted");
                }

                return("Clothe does not exist");
            }
        }