Example #1
0
        // POST api/<controller>
        public HttpResponseMessage Post(Api_Models.MstBorrower_ApiModel objBorrower)
        {
            try
            {
                Data.MstBorrower newUser = new Data.MstBorrower
                {
                    BorrowerNumber       = objBorrower.BorrowerNumber,
                    ManualBorrowerNumber = objBorrower.ManualBorrowerNumber,
                    FullName             = objBorrower.FullName,
                    Department           = objBorrower.Department,
                    Course          = objBorrower.Course,
                    CreatedByUserId = objBorrower.CreatedByUserId,
                    CreatedDate     = objBorrower.CreatedDate,
                    UpdatedByUserId = objBorrower.UpdatedByUserId,
                    UpdatedDate     = objBorrower.UpdatedDate,
                    BorrowerTypeId  = objBorrower.BorrowerTypeId,
                    LibraryCardId   = objBorrower.LibraryCardId
                };
                db.MstBorrowers.InsertOnSubmit(newUser);
                db.SubmitChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
        public HttpResponseMessage AddBorrwer(Entities.MstBorrower objLibraryBorrower)
        {
            try
            {
                var borrower = from d in db.MstBorrowers
                               where d.Id == objLibraryBorrower.Id
                               select d;



                if (borrower.Any())
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Book No. already taken!"));
                }
                else
                {
                    var currentUser = from d in db.MstUsers
                                      where d.AspNetUserId == User.Identity.GetUserId()
                                      select d;

                    Data.MstBorrower newBorrower = new Data.MstBorrower
                    {
                        BorrowerNumber       = objLibraryBorrower.BorrowerNumber,
                        ManualBorrowerNumber = objLibraryBorrower.ManualBorrowerNumber,
                        FullName             = objLibraryBorrower.FullName,
                        Department           = objLibraryBorrower.Department,
                        Course = objLibraryBorrower.Course,
                        // CreatedByUserId = objLibraryBorrower.UpdatedByUserId,
                        CreatedByUserId = currentUser.FirstOrDefault().Id,
                        CreatedDate     = DateTime.Now,
                        //UpdatedByUserId = objLibraryBorrower.UpdatedByUserId,
                        UpdatedByUserId = currentUser.FirstOrDefault().Id,
                        UpdatedDate     = DateTime.Now,
                        BorrowerTypeId  = objLibraryBorrower.BorrowerTypeId,
                        LibraryCardId   = objLibraryBorrower.LibraryCardId
                    };

                    db.MstBorrowers.InsertOnSubmit(newBorrower);
                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
Example #3
0
        public HttpResponseMessage AddBorrower(ApiModels.MstBorrowerModel objBorrower)
        {
            try
            {
                Data.MstBorrower newBorrower = new Data.MstBorrower
                {
                     BorrowerNumber = objBorrower.BorrowerNumber,
                     ManualBorrowerNumber = objBorrower.ManualBorrowerNumber,
                     FullName = objBorrower.FullName,
                     Department = objBorrower.Department,
                     Course = objBorrower.Course,
                     CreatedByUserId =objBorrower.CreatedByUserId,
                     CreatedDate = objBorrower.CreatedDate,
                     UpdatedByUserId = objBorrower.UpdatedByUserId,
                     UpdatedDate = objBorrower.UpdatedDate,
                     BorrowerTypeId = objBorrower.BorrowerTypeId,
                     LibraryCardId = objBorrower.LibraryCardId
                };
                };
                db.MstBorrower.InsertOnSubmit(newBorrower);
                db.SubmitChanges();

                return Request.CreateResponse(HttpStatusCode.OK);
            }