Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am filling student issue book form,in that form i adding multiple books for same student in list box control.and i want to save them in database.with different issue id of same student each save different book id's in table.
I am also not getting values at Student_Issue_BookObj of create method

What I have tried:

here is the post method of controller
C#
 [HttpPost]
        public ActionResult Create(CustomBook1 Student_Issue_BookObj)
        {
            try
            {
                var Student_BookObj = Student_Issue_BookObj.CustomBook;
                //Student_Issue_BookObj.Last_Updated_By = CurrentUserID;
                //Student_Issue_BookObj.Last_Updated_Date = DateTime.Now.ToUniversalTime();
                //Student_Issue_BookObj.Created_By = CurrentUserID;
                //Student_Issue_BookObj.Creation_Date = DateTime.Now.ToUniversalTime();
                //Student_Issue_BookObj.Status = true;
                // var selectedBook = Student_BookObj.Where(a => a.Status == true).ToList();
                var selectedBook = Student_BookObj.ToList();

                foreach (var BookIssue in selectedBook)
                {
                    Student_Issue_Book CUSTOM_Book_IssueObj = new Student_Issue_Book();
                    CUSTOM_Book_IssueObj.Book_Id = BookIssue.Book_Id;

                    CUSTOM_Book_IssueObj.Class_Id = BookIssue.Class_Id;
                    CUSTOM_Book_IssueObj.Section_Id = BookIssue.Section_Id;
                    CUSTOM_Book_IssueObj.Book_Category_Id = BookIssue.Book_Category_Id;
                    CUSTOM_Book_IssueObj.Registration_Id = BookIssue.Registration_Id;
                    CUSTOM_Book_IssueObj.Roll_Id = BookIssue.Roll_Id;
                    CUSTOM_Book_IssueObj.Issue_Date = BookIssue.Issue_Date;
                    CUSTOM_Book_IssueObj.Return_Date = BookIssue.Return_Date;
                    CUSTOM_Book_IssueObj.Academic_year_Id = BookIssue.Academic_year_Id;
                    CUSTOM_Book_IssueObj.Last_Updated_By = CurrentUserID;
                    CUSTOM_Book_IssueObj.Last_Updated_Date = DateTime.Now.ToUniversalTime();
                    if (BookIssue.Issue_Return_Id > 0)
                    {
                        CUSTOM_Book_IssueObj.Issue_Return_Id = BookIssue.Issue_Return_Id;
                        if (_CRUDrepository.UpdateObjectInfo(CUSTOM_Book_IssueObj, "Issue_Return_Id"))
                        { }
                    }
                    else
                    {
                        if (_CRUDrepository.CreateNewObject(CUSTOM_Book_IssueObj, "Issue_Return_Id"))
                        { }
                    }

                }
                ModelState.AddModelError("", "All Authorization allocated successfully....");
                FillViewBag();
                Response.Redirect("Index");
                return View();

            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Error Allocating Authorization.." + ex.Message.ToString());
                FillViewBag();
                return View();
            }
        }

Here is my classes
   public class CustomBook1
        {
            public List<custombook> CustomBook { get; set; }
        }
        public class CustomBook
        {
            public long? Book_Id { get; set; }
         
            public DateTime? Issue_Date { get; set; }
            public DateTime? Return_Date { get; set; }
            public long? Academic_year_Id { get; set; }
            public long? Class_Id { get; set; }
            public long? Section_Id { get; set; }
            public long? Book_Category_Id { get; set; }
            public long? Roll_Id { get; set; }
            public bool Status { get; set; }
            public long? Registration_Id { get; set; }
             public long Issue_Return_Id { get; set; }
           
        }</custombook>
Posted
Updated 15-Mar-16 0:02am
v3
Comments
Hussain Javed 16-Mar-16 1:44am    
I am not getting values from list class to post method of create
here is my classes
public class CUSTOM_STUDENT_FEEALLOCATION_DETAIL
{

public long? Registration_Id { get; set; }
public long? Admission_No { get; set; }
public long? Class_Id { get; set; }
public long? Academic_Year_Id { get; set; }
public long? Book_ID { get; set; }
public string Academic_Year_Name { get; set; }
public string Book_category_Name { get; set; }
public string Period_Name { get; set; }
public string Book_Name { get; set; }
public DateTime? Issue_Date { get; set; }
public DateTime? returnDate { get; set; }
public bool? Status { get; set; }
public decimal? Final_Amount { get; set; }
public bool SELECTED_STUDENT { get; set; }
public long? issue_Return_Id { get; set; }
public long? book_category_id { get; set; }
public long? Academic_year_Id { get; set; }
public long Issue_Return_Id { get; set; }
public String STUDENT_NAME { get; set; }



}
public class CUSTOM_STUDENT_FEEALLOCTION_DATA
{
public List<custom_student_feeallocation_detail> CUSTOM_STUDENT_FEEALLOCATION_DETAIL { get; set; }

}
here is my method

[HttpPost]
public ActionResult Index(CUSTOM_STUDENT_FEEALLOCTION_DATA CUSTOM_STUDENT_FEEALLOCTION_DATAObj)
{

var Student_FeeallocationDetail = CUSTOM_STUDENT_FEEALLOCTION_DATAObj.CUSTOM_STUDENT_FEEALLOCATION_DETAIL;
var SelectStufeedetail = Student_FeeallocationDetail.Where(b => b.SELECTED_STUDENT == true).ToList();

CUSTOM_STU_DETAIL stuentdetail = new CUSTOM_STU_DETAIL();
try
{
foreach (var studentfeedatal in SelectStufeedetail)
{
var fee_set = db.Student_Issue_Book.Where(a => a.Book_Id == studentfeedatal.Book_ID && a.Registration_Id == studentfeedatal.Registration_Id).ToList();
if (fee_set.Count != 0)
{
Student_Issue_Book Student_Fee_AlloctionObj = new Student_Issue_Book();
Student_Fee_AlloctionObj.Last_Updated_Date = DateTime.Now.ToUniversalTime();
Student_Fee_AlloctionObj.Last_Updated_By = CurrentUserID;
Student_Fee_AlloctionObj.Creation_Date = DateTime.Now.ToUniversalTime();
Student_Fee_AlloctionObj.Created_By = CurrentUserID;
// Student_Fee_AlloctionObj.Book_Category_Id = studentfeedatal.Book_Category_Id;
Student_Fee_AlloctionObj.Book_Id = studentfeedatal.Book_ID;
Student_Fee_AlloctionObj.Class_Id = studentfeedatal.Class_Id;
Student_Fee_AlloctionObj.Status = false;
Student_Fee_AlloctionObj.Issue_Return_Id = studentfeedatal.Issue_Return_Id;
Student_Fee_AlloctionObj.Registration_Id = studentfeedatal.Registration_Id;
Student_Fee_AlloctionObj.Issue_Date = studentfeedatal.Issue_Date;
Student_Fee_AlloctionObj.Return_Date = DateTime.Now.ToUniversalTime();
Student_Fee_AlloctionObj.Academic_year_Id = studentfeedatal.Academic_year_Id;
Student_Fee_AlloctionObj.Delete_Flag = true;
//Student_Fee_AlloctionObj.Final_Amount = studentfeedatal.Final_Amount;
if (_CRUDrepository.UpdateObjectInfo(Student_Fee_AlloctionObj, "Issue_Return_Id"))
{
//_CRUDrepository.CreateNewObject(Student_Fee_AlloctionObj);
// return RedirectToAction("Index");
}

}
else

1 solution

 
Share this answer
 
Comments
Hussain Javed 15-Mar-16 7:00am    
I am not getting values at Student_Issue_BookObj of create method.
I have list box in which i get multiple books to one student.and want to save these books to same student with generating different id's in database.
F-ES Sitecore 15-Mar-16 7:13am    
It's impossible to help with what you're posted, you've only posted the action and I'm assuming you are looking to get a list of data rather than a single object, if that's not the case then please clarify, and also update the post to contain the relevant parts of the view also.
Hussain Javed 15-Mar-16 7:19am    
i want to show the form design at front,how can i post word file to you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900