public HttpResponseMessage addLibraryBook(Entities.MtsLibraryBook objLibraryBook) { try { var currentUserType = from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d.MstUserType.UserType; var userType = currentUserType.FirstOrDefault(); if (userType == "Admin") { var bookNumber = from d in db.MstLibraryBooks where d.BookNumber == objLibraryBook.BookNumber select d.BookNumber; if (bookNumber.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.MstLibraryBook newLibraryBook = new Data.MstLibraryBook { BookNumber = objLibraryBook.BookNumber, Title = objLibraryBook.Title, Author = objLibraryBook.Author, EditionNumber = objLibraryBook.EditionNumber, PlaceOfPublication = objLibraryBook.PlaceOfPublication, CopyRightDate = Convert.ToDateTime(objLibraryBook.CopyRightDate), ISBN = objLibraryBook.ISBN, CreatedByUserId = currentUser.FirstOrDefault().Id, CreatedBy = currentUser.FirstOrDefault().FirstName, CreatedDate = DateTime.Now, UpdatedByUserId = currentUser.FirstOrDefault().Id, UpdatedBy = currentUser.FirstOrDefault().FirstName, UpdatedDate = DateTime.Now, }; db.MstLibraryBooks.InsertOnSubmit(newLibraryBook); db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You're not authorize!")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
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.")); } }
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.")); } }
public HttpResponseMessage AddLibraryCard(Entities.MstLibraryCard objLibraryCard) { try { var libraryCard = from d in db.MstLibaryCards where d.Id == objLibraryCard.Id && d.LibraryCardNumber == objLibraryCard.LibraryCardNumber select d; if (libraryCard.Any()) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Library card already exist!")); } else { var currentUser = from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d; Data.MstLibaryCard newLibraryCard = new Data.MstLibaryCard { LibraryCardNumber = objLibraryCard.LibraryCardNumber, ManualLibraryCardNumber = objLibraryCard.ManualLibraryCardNumber, BorrowerId = objLibraryCard.BorrowerId, IsPrinted = objLibraryCard.IsPrinted, LibraryInChargeUserId = currentUser.FirstOrDefault().Id, FootNote = objLibraryCard.FootNote, CreatedByUserId = currentUser.FirstOrDefault().Id, CreatedDate = DateTime.Now, UpdatedByUserId = currentUser.FirstOrDefault().Id, UpdatedDate = DateTime.Now, }; db.MstLibaryCards.InsertOnSubmit(newLibraryCard); 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.")); } }
public HttpResponseMessage AddUser(Entities.MstUser objMstUser) { try { Data.MstUser mstUser = new Data.MstUser { FirstName = objMstUser.FirstName, LastName = objMstUser.LastName, Password = objMstUser.Password, UserTypeId = objMstUser.UserTypeId, }; db.MstUsers.InsertOnSubmit(mstUser); 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.")); } }
public async Task <IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = model.Username, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } else { Data.librarydbDataContext db = new Data.librarydbDataContext(); Data.MstUser mstUser = new Data.MstUser { FirstName = model.FirstName, LastName = model.LastName, Password = model.Password, UserTypeId = model.UserTypeId, AspNetUserId = user.Id }; db.MstUsers.InsertOnSubmit(mstUser); db.SubmitChanges(); return(Ok()); } }