예제 #1
0
        public HttpResponseMessage AddTrnBorrow(ApiModels.TrnBorrow objTrnBorrow)
        {
            try
            {
                Data.TrnBorrow newTrnBorrow = new Data.TrnBorrow
                {
                    Id                 = objTrnBorrow.Id,
                    BorrowNumber       = objTrnBorrow.BookNumber,
                    BookNumber         = objTrnBorrow.BookNumber,
                    BorrowDate         = objTrnBorrow.BorrowDate,
                    ManualBorrowNumber = objTrnBorrow.ManualBorrowNumber,
                    BorrowerId         = objTrnBorrow.BorrowerId,
                    LibraryCardId      = objTrnBorrow.LibraryCardId,
                    PreparedByUser     = objTrnBorrow.PreparedByUser,
                    CreatedByUserId    = objTrnBorrow.CreatedByUserId,
                    CreatedDate        = objTrnBorrow.CreatedDate,
                    UpdatedByUserId    = objTrnBorrow.UpdatedByUserId,
                    UpdatedDate        = objTrnBorrow.UpdatedDate
                };
                db.TrnBorrows.InsertOnSubmit(newTrnBorrow);
                db.SubmitChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
        // POST api/<controller>
        public HttpResponseMessage Post(Api_Models.TrnBorrow_ApiModel objBorrows)
        {
            try
            {
                Data.TrnBorrow newBorrows = new Data.TrnBorrow
                {
                    BorrowNumber       = objBorrows.BorrowNumber,
                    BookNumber         = objBorrows.BookNumber,
                    BorrowDate         = objBorrows.BorrowDate,
                    ManualBorrowNumber = objBorrows.ManualBorrowNumber,
                    BorrowerId         = objBorrows.BorrowerId,
                    LibrryCardId       = objBorrows.LibraryCardId,
                    PreparedByUser     = objBorrows.PreparedByUser,
                    CreatedByUserId    = objBorrows.CreatedByUserId,
                    CreatedDate        = objBorrows.CreatedDate,
                    UpdatedByUserId    = objBorrows.UpdatedByUserId,
                    UpdatedDate        = objBorrows.UpdatedDate,
                };
                db.TrnBorrows.InsertOnSubmit(newBorrows);
                db.SubmitChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
예제 #3
0
        public HttpResponseMessage AddTrnBorrow(Entities.TrnBorrow objTrnBorrow)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.AspNetUserId == User.Identity.GetUserId()
                                  select d;

                if (!currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    Data.TrnBorrow newTrnBorrow = new Data.TrnBorrow
                    {
                        BorrowNumber       = objTrnBorrow.BorrowNumber,
                        BorrowDate         = Convert.ToDateTime(objTrnBorrow.BorrowDate),
                        ManualBorrowNumber = objTrnBorrow.ManualBorrowNumber,
                        BorrowerId         = objTrnBorrow.BorrowerId,
                        LibraryCardId      = objTrnBorrow.LibraryCardId,
                        PreparedByUser     = objTrnBorrow.PreparedByUser,
                        CreatedByUserId    = currentUserId,
                        CreatedDate        = DateTime.Now,
                        UpdatedByUserId    = currentUserId,
                        UpdatedDate        = DateTime.Now
                    };

                    db.TrnBorrows.InsertOnSubmit(newTrnBorrow);
                    db.SubmitChanges();

                    Int32 BorrowId = newTrnBorrow.Id;

                    if (objTrnBorrow.ListOfBooks.Any())
                    {
                        List <Data.TrnBorrowBook> newBookBorrows = new List <Data.TrnBorrowBook>();

                        foreach (var Book in objTrnBorrow.ListOfBooks)
                        {
                            newBookBorrows.Add(new Data.TrnBorrowBook
                            {
                                BorrowId = BorrowId,
                                BookId   = Book.BookId,
                                Quantity = Book.Quantity
                            });
                        }
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid transaction!"));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }