コード例 #1
0
 /// <summary>
 /// Update the abstract book associated with the spcified AbstractBookModel instance.
 /// </summary>
 /// <param name="abstractBook">The AbstractBookModel entity instance to update.</param>
 public void Update(AbstractBookModel abstractBook)
 {
     try
     {
         using (Context context = new Context())
         {
             context.AbstractBooks.Attach(abstractBook);
             context.Entry(abstractBook).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         logsRepository.Add(e.Message);
     }
 }
コード例 #2
0
        /// <summary>
        /// Adds an abstract book to the database.
        /// </summary>
        /// <param name="abstarctBook">The AbstractBookModel entity instance to add.</param>
        /// <returns>A fully populated AbstarctBookModel entity instance.</returns>
        public AbstractBookModel Add(AbstractBookModel abstractBook)
        {
            try
            {
                using (Context context = new Context())
                {
                    context.AbstractBooks.Add(abstractBook);
                    context.SaveChanges();

                    return(abstractBook);
                }
            }
            catch (Exception e)
            {
                logsRepository.Add(e.Message);
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Posts new book to the server.
        /// </summary>
        public void AddBook()
        {
            AbstractBookModel   abstractBook = null;
            HttpResponseMessage httpResponse = null;

            if (IsJournal)
            {
                abstractBook = GetJournal();
                if (abstractBook != null)
                {
                    httpResponse = ConstantsHelper.Post(abstractBook, booksApiUrl + "/PostJournal", httpClient);
                    var addedBook = httpResponse.Content.ReadAsAsync <JournalModel>().Result;
                    Journals.Add(addedBook);
                }
            }
            else if (IsBook)
            {
                abstractBook = GetBook();
                if (abstractBook != null)
                {
                    httpResponse = ConstantsHelper.Post(abstractBook, booksApiUrl + "/PostBooks", httpClient);
                    var addedBook = httpResponse.Content.ReadAsAsync <BookModel>().Result;
                    Books.Add(addedBook);
                }
            }
            else
            {
                Message = "Book or journal must be choose";
            }


            if (httpResponse != null)
            {
                if (httpResponse.IsSuccessStatusCode)
                {
                    Message = $"{abstractBook.Name} has been added successfully";
                }

                else
                {
                    Message = "There was an error! check the fields to see if anything is missing";
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Adds a purchase to the database.
        /// </summary>
        /// <param name="purchase">The PurchaseModel entity instance to add.</param>
        /// <returns>A fully populated PurchaseModel entity instance.</returns>
        public PurchaseModel Add(PurchaseModel purchase)
        {
            try
            {
                using (Context context = new Context())
                {
                    AbstractBookModel book = context.AbstractBooks.Find(purchase.AbstractBookId);

                    purchase.TotalPrice = (book.DiscountPercentage / 100) * book.Price;

                    context.Purchases.Add(purchase);
                    context.SaveChanges();


                    return(context.Purchases.Include(p => p.AbstractBook).Include(p => p.Customer).Include(p => p.Employee).FirstOrDefault(p => p.Id == purchase.Id));
                }
            }
            catch (Exception e)
            {
                logsRepository.Add(e.Message);
            }

            return(null);
        }