Beispiel #1
0
        public int ChangeBookStatus(int bookrequestDetailId, int status, string userID, string note)
        {
            BookRequestDetail detail = this._bookRequestDetailRepository.Table.FirstOrDefault(w => w.Id == bookrequestDetailId);

            if (detail != null)
            {
                detail.Status    = status;
                detail.UpdatedBy = userID;
                detail.UpdatedOn = DateTime.Now;
                detail.Notes     = note;
                this._bookRequestDetailRepository.Update(detail);
                return(detail.BookId);
            }
            else
            {
                return(0);
            }
        }
Beispiel #2
0
        public JsonNetResult SaveStudent(Student student, List <Book> books, College college, BookRequest bookRequest)
        {
            try
            {
                //if (!ModelState.IsValid)
                //{
                //    return JsonNet(new ReturnData { Message = "Please fill all required information." }, JsonRequestBehavior.AllowGet);
                //}

                //VALIDATION FOR BOOK REQUEST
                if (books == null || !books.Any())
                {
                    return(JsonNet(new ReturnData {
                        Message = "Please add atleast one book."
                    }, JsonRequestBehavior.AllowGet));
                }

                for (int i = 0; i < books.Count(); i++)
                {
                    Book book = books[i];
                    if (!string.IsNullOrEmpty(book.Title) || !string.IsNullOrEmpty(book.Author) || !string.IsNullOrEmpty(book.Publication) || !string.IsNullOrEmpty(book.Subject))
                    {
                        if (string.IsNullOrEmpty(book.Title) || string.IsNullOrEmpty(book.Author) || string.IsNullOrEmpty(book.Publication) || string.IsNullOrEmpty(book.Subject))
                        {
                            return(JsonNet(new ReturnData {
                                Message = string.Format("Information for SrNo: {0} not filled properly.", i + 1)
                            }, JsonRequestBehavior.AllowGet));
                        }
                    }
                }


                //VALIDATION FOR STUDENT PERSONAL INFO
                if (student.FirstName == null || student.LastName == null || bookRequest.CollegeId == null || bookRequest.BranchId == null || student.ImagePath == "")
                {
                    return(JsonNet(new ReturnData {
                        Message = "Please fill all personal information."
                    }, JsonRequestBehavior.AllowGet));
                }


                //System.Threading.Thread.Sleep(1000 * 5);
                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))                                                                                                                                                  // Testing Required...
                {
                    // var user = new ApplicationUser { UserName = student.Email, Email = student.Email };
                    //  var result = UserManager.Create(user, "Abc123#");


                    //UserManager.AddToRole(user.Id, "Student");

                    student.UserId = User.Identity.GetUserId();

                    //Insert college if new
                    if (college.Name != null)
                    {
                        college.CreatedOn     = DateTime.Now;
                        bookRequest.CollegeId = this._collegeBranchService.InsertCollege(college);
                    }

                    //Insert Student

                    int studentId = student.Id;
                    if (studentId <= 0)
                    {
                        student.CreatedBy = User.Identity.GetUserId();
                        student.CreatedOn = DateTime.Now;
                        studentId         = this._studentService.Insert(student);
                    }
                    else
                    {
                        student.UpdatedBy = User.Identity.GetUserId();
                        student.UpdatedOn = DateTime.Now;
                        this._studentService.Update(student);
                    }
                    //Insert Request

                    bookRequest.StudentId = studentId;
                    // bookRequest.CollegeId = student.CollegeId;
                    //  bookRequest.BranchId = student.BranchId;
                    bookRequest.RequestDate = DateTime.Now;
                    bookRequest.CreatedBy   = User.Identity.GetUserId();
                    bookRequest.CreatedOn   = DateTime.Now;
                    int bookRequestId = this._bookRequestService.InsertBookRequest(bookRequest);


                    //Insert Request Detail (Check New book or old book
                    NewBookRequestDetail newBookRequestDetail;

                    foreach (var book in books)
                    {
                        if (string.IsNullOrEmpty(book.Title))
                        {
                            continue;
                        }

                        BookRequestDetail bookRequestDetail;
                        if (book.Title.IsInt())
                        {
                            bookRequestDetail           = new BookRequestDetail();
                            bookRequestDetail.BookId    = int.Parse(book.Title);
                            bookRequestDetail.RequestId = bookRequestId;
                            bookRequestDetail.Status    = (int)BookRequestStatus.Pending;
                            bookRequestDetail.Subject   = book.Subject;
                            this._bookRequestService.InsertBookRequestDetail(bookRequestDetail);
                        }
                        else
                        {
                            // book.IsNew = true;
                            int bookId = this._bookService.Insert(book);

                            bookRequestDetail           = new BookRequestDetail();
                            bookRequestDetail.BookId    = bookId;
                            bookRequestDetail.RequestId = bookRequestId;
                            bookRequestDetail.Status    = (int)BookRequestStatus.Pending;
                            bookRequestDetail.Subject   = book.Subject;
                            this._bookRequestService.InsertBookRequestDetail(bookRequestDetail);
                        }
                    }

                    scope.Complete();
                    // /Images/tempFile.jpg

                    try
                    {
                        if (!String.IsNullOrEmpty(student.ImagePath) && studentId != 0)
                        {
                            int    index = student.ImagePath.LastIndexOf('.');
                            string ext   = student.ImagePath.Substring(index + 1);

                            string subPath = Server.MapPath("../Uploads/ProfilePics"); // your code goes here
                            //  System.IO.File.Move(subPath+"//"+student.ImagePath,subPath+"//"+"st"+studentID+ext);
                            FileInfo file    = new FileInfo(subPath + "\\" + student.ImagePath);
                            string   newName = "\\st" + studentId + "." + ext;
                            file.CopyTo(subPath + newName, true);
                            file.Delete();
                            student.ImagePath = newName;
                            this._studentService.Update(student);
                        }
                    }
                    catch (Exception ex)
                    {
                    }

                    //studentID
                    return(JsonNet(new ReturnData {
                        Message = "Success"
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(JsonNet(new ReturnData {
                    Message = "Oops! registration failed. Please contact administrator."
                }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #3
0
        public JsonNetResult BookRequest(BookRequestViewModel model, string button)
        {
            //if (button.Equals("AddNew", StringComparison.OrdinalIgnoreCase))
            //{
            //    if (model.BookRequestDetails == null)
            //        model.BookRequestDetails = new List<BookRequestDetail>();
            //    int Id = model.BookRequestDetails.Max(m => m.Id) + 1;
            //    model.BookRequestDetails.Add(new BookRequestDetail { Id = Id });
            //}
            //else if (button.StartsWith("DeleteRow", StringComparison.OrdinalIgnoreCase))
            //{
            //    int Id = Convert.ToInt32(button.Split('_')[1]);
            //    model.BookRequestDetails = model.BookRequestDetails.Where(w => w.Id != Id).ToList();
            //}

            try
            {
                string userId = User.Identity.GetUserId();
                //model.Student = this._studentService.GetStudentByUserId(userId);
                if (!ModelState.IsValid)
                {
                    JsonResponse response = new JsonResponse {
                        Messages = new List <string>(), MsgType = MessageType.Validations
                    };
                    foreach (ModelState modelState in ViewData.ModelState.Values)
                    {
                        foreach (ModelError error in modelState.Errors)
                        {
                            response.Messages.Add(error.ErrorMessage);
                        }
                    }
                    return(JsonNet(response, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var bookRequestDetails = model.BookRequestDetails.Where(w => !string.IsNullOrEmpty(w.Subject) && !string.IsNullOrEmpty(w.Title) &&
                                                                            !string.IsNullOrEmpty(w.Publication) && !string.IsNullOrEmpty(w.Author)).ToList();

                    var partialBookRequests = model.BookRequestDetails.Where(w => !bookRequestDetails.Contains(w) && (!string.IsNullOrEmpty(w.Subject) || !string.IsNullOrEmpty(w.Title) ||
                                                                                                                      !string.IsNullOrEmpty(w.Publication) || !string.IsNullOrEmpty(w.Author))).ToList();

                    var messages = new List <string>();

                    if (string.Equals(model.College.Name.Trim(), "Other", StringComparison.OrdinalIgnoreCase))
                    {
                        messages.Add("College name is not allowed.");
                    }
                    if (string.Equals(model.Branch.Name.Trim(), "Other", StringComparison.OrdinalIgnoreCase))
                    {
                        messages.Add("Branch name is not allowed");
                    }

                    if (partialBookRequests.Any())
                    {
                        for (int i = 0; i < partialBookRequests.Count; i++)
                        {
                            if (string.IsNullOrEmpty(partialBookRequests[i].Subject))
                            {
                                messages.Add(string.Format("Subject required for Sr.no. {0}.", partialBookRequests[i].Id));
                            }
                            if (string.IsNullOrEmpty(partialBookRequests[i].Title))
                            {
                                messages.Add(string.Format("Title required in Sr.no. {0}.", partialBookRequests[i].Id));
                            }
                            if (string.IsNullOrEmpty(partialBookRequests[i].Publication))
                            {
                                messages.Add(string.Format("Publication required in Sr.no. {0}.", partialBookRequests[i].Id));
                            }
                            if (string.IsNullOrEmpty(partialBookRequests[i].Author))
                            {
                                messages.Add(string.Format("Author required in Sr.no. {0}.", partialBookRequests[i].Id));
                            }
                        }
                    }
                    else if (!bookRequestDetails.Any())
                    {
                        messages.Add("Atleast one text book request is required.");
                    }

                    if (messages.Any())
                    {
                        return(JsonNet(new JsonResponse {
                            MsgType = MessageType.Validations, Messages = messages
                        }, JsonRequestBehavior.AllowGet));
                    }
                    using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                        IsolationLevel = IsolationLevel.ReadCommitted
                    }))                                                                                                                                                  // Testing Required...
                    {
                        if (model.College.Id <= 0)
                        {
                            model.College.CreatedOn = DateTime.Now;
                            model.College.Id        = this._collegeBranchService.InsertCollege(model.College);
                        }

                        if (model.Branch.Id <= 0)
                        {
                            model.Branch.CreatedOn = DateTime.Now;
                            model.Branch.Id        = this._collegeBranchService.InsertBranch(model.Branch);
                        }

                        //model.Student.UserId = userId;
                        if (model.Student.Id > 0)
                        {
                            model.Student.UpdatedBy = userId;
                            model.Student.UpdatedOn = DateTime.Now;
                            //model.Student.EnrollmentNo = String.Format("{0}-{1}-{2}-A", DateTime.Now.ToString("yy"), model.Branch.Name.Substring(0, 2), model.Student.Id.ToString("0000"));
                            //this._studentService.Update(model.Student); // Student can not update. Need to request admin to update info
                        }
                        else
                        {
                            model.Student.CreatedBy    = userId;
                            model.Student.CreatedOn    = DateTime.Now;
                            model.Student.EnrollmentNo = "E";
                            model.Student.Id           = this._studentService.Insert(model.Student);
                            string[] branchNameArray = model.Branch.Name.Split(new char[] { ' ' });
                            if (branchNameArray.Length >= 2)
                            {
                                model.Student.EnrollmentNo = String.Format("{0}-{1}{2}-{3}-A", DateTime.Now.ToString("yy"), branchNameArray[0][0].ToString().ToUpper(), branchNameArray[1][0].ToString().ToUpper(), model.Student.Id.ToString("0000"));
                            }
                            else
                            {
                                model.Student.EnrollmentNo = String.Format("{0}-{1}-{2}-A", DateTime.Now.ToString("yy"), model.Branch.Name.Substring(0, 2).ToUpper(), model.Student.Id.ToString("0000"));
                            }
                            this._studentService.Update(model.Student); // Student can not update. Need to request admin if require any change
                        }

                        model.BookRequest.StudentId   = model.Student.Id;
                        model.BookRequest.CollegeId   = model.College.Id;
                        model.BookRequest.BranchId    = model.Branch.Id;
                        model.BookRequest.Subject     = "NA";
                        model.BookRequest.RequestDate = DateTime.Now;
                        model.BookRequest.CreatedBy   = userId;
                        model.BookRequest.CreatedOn   = DateTime.Now;
                        model.BookRequest.Id          = this._bookRequestService.InsertBookRequest(model.BookRequest);

                        foreach (var item in bookRequestDetails)
                        {
                            int bookId = 0;
                            int.TryParse(item.BookId, out bookId);
                            item.BookId = Convert.ToString(bookId);

                            Book existingBook = null;
                            if (bookId > 0)
                            {
                                existingBook = this._bookService.GetBookById(bookId);
                            }

                            if (existingBook != null)
                            {
                                item.Title = existingBook.Title;
                                if ((!existingBook.Author.Equals(item.Author, StringComparison.OrdinalIgnoreCase) || !existingBook.Publication.Equals(item.Publication, StringComparison.OrdinalIgnoreCase)))
                                {
                                    bookId      = 0;
                                    item.BookId = "0";
                                }
                            }

                            if (bookId <= 0)
                            {
                                var book = new Book
                                {
                                    Title            = item.Title,
                                    Author           = item.Author,
                                    Subject          = item.Subject,
                                    Publication      = item.Publication,
                                    IsNewRequest     = true,
                                    TotalBooks       = 0,
                                    ApprovedBooks    = 0,
                                    NewApprovedBooks = 0,
                                    IssuedBooks      = 0,
                                    TornBooks        = 0,
                                    AvailableBooks   = 0
                                };
                                bookId      = this._bookService.Insert(book);
                                item.BookId = Convert.ToString(bookId);
                            }

                            var bookRequestDetail = new BookRequestDetail
                            {
                                RequestId = model.BookRequest.Id,
                                BookId    = bookId,
                                Status    = (int)BookRequestStatus.Pending,
                                Subject   = item.Subject
                            };

                            item.Id = this._bookRequestService.InsertBookRequestDetail(bookRequestDetail);
                            this._historyService.InsertBookRequestHistory(new BookRequestHistory {
                                BookRequestDetailId = item.Id, Status = (int)BookRequestStatus.Pending, CreatedBy = userId, CreatedOn = DateTime.Now
                            });
                        }
                        scope.Complete();
                    }

                    var emailText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/EmailTemplates/RequestReceived.html"));
                    emailText = emailText.Replace("{{BASE_URL}}", _webHelper.GetStoreHost(false));
                    System.Web.UI.WebControls.Table tbl = new System.Web.UI.WebControls.Table();
                    tbl.BorderColor = Color.Black;
                    tbl.BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
                    tbl.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
                    tbl.Width       = System.Web.UI.WebControls.Unit.Percentage(100);
                    System.Web.UI.WebControls.TableRow  tr   = null;
                    System.Web.UI.WebControls.TableCell col1 = null;
                    System.Web.UI.WebControls.TableCell col2 = null;
                    System.Web.UI.WebControls.TableCell col3 = null;
                    System.Web.UI.WebControls.TableCell col4 = null;
                    System.Web.UI.WebControls.TableCell col5 = null;

                    tr   = new System.Web.UI.WebControls.TableRow();
                    col1 = new System.Web.UI.WebControls.TableCell();
                    col2 = new System.Web.UI.WebControls.TableCell();
                    col3 = new System.Web.UI.WebControls.TableCell();
                    col4 = new System.Web.UI.WebControls.TableCell();
                    col5 = new System.Web.UI.WebControls.TableCell();

                    col1.Text = "Sr#";
                    col2.Text = "Subject";
                    col3.Text = "Title";
                    col4.Text = "Author";
                    col5.Text = "Publication";
                    col1.Style.Add("font-weight", "bold");
                    col2.Style.Add("font-weight", "bold");
                    col3.Style.Add("font-weight", "bold");
                    col4.Style.Add("font-weight", "bold");
                    col5.Style.Add("font-weight", "bold");

                    tr.Cells.AddRange(new System.Web.UI.WebControls.TableCell[] { col1, col2, col3, col4, col5 });
                    tbl.Rows.Add(tr);
                    int j = 0;
                    foreach (var item in bookRequestDetails)
                    {
                        j   += 1;
                        tr   = new System.Web.UI.WebControls.TableRow();
                        col1 = new System.Web.UI.WebControls.TableCell();
                        col2 = new System.Web.UI.WebControls.TableCell();
                        col3 = new System.Web.UI.WebControls.TableCell();
                        col4 = new System.Web.UI.WebControls.TableCell();
                        col5 = new System.Web.UI.WebControls.TableCell();

                        col1.Text = Convert.ToString(j);
                        col2.Text = item.Subject;
                        col3.Text = item.Title;
                        col4.Text = item.Author;
                        col5.Text = item.Publication;
                        tr.Cells.AddRange(new System.Web.UI.WebControls.TableCell[] { col1, col2, col3, col4, col5 });
                        tbl.Rows.Add(tr);
                    }

                    StringBuilder sb = new StringBuilder();
                    System.Web.UI.HtmlTextWriter ht = new System.Web.UI.HtmlTextWriter(new System.IO.StringWriter(sb));
                    tbl.RenderControl(ht);
                    string html = ht.InnerWriter.ToString();

                    emailText = emailText.Replace("{{BOOK_REQUESTS}}", html);
                    UserManager.SendEmail(model.Student.UserId, "Book Request Received", emailText);

                    return(JsonNet(new JsonResponse {
                        MsgType = MessageType.Success, Messages = new List <string>(), RedirectUrl = Url.Action("RequestSuccess", "Library", null, Request.Url.Scheme)
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                ErrorNotification(ex);
                var messages = new List <string>();
                messages.Add(ex.Message + ex.InnerException ?? ex.InnerException.Message);
                return(JsonNet(new JsonResponse {
                    MsgType = MessageType.Error, Messages = messages
                }, JsonRequestBehavior.AllowGet));
            }
            //return PartialView("_BookRequestDetails", model.BookRequestDetails);
        }
Beispiel #4
0
 public int InsertBookRequestDetail(BookRequestDetail bRequestDetail)
 {
     this._bookRequestDetailRepository.Insert(bRequestDetail);
     return(bRequestDetail.Id);
 }