Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is the bookingview model
public class BookingView
   {
       public string treatment { get; set; }

       public string TreatmentName { get; set; }

       public int bookingID { get; set; }

       public int clientID { get; set; }

       public int treatmentID { get; set; }

       public DateTime date { get; set; }

       public String location { get; set; }

       public double cost { get; set; }

       public int numberOfPeole { get; set; }

       public String status { get; set; }

       public double treatmentCost { get; set; }

       public bool Check { get; set; }

       public  List<TreatmentView> Treatmentses { get; set; }

this is the treatmentview model
public class TreatmentView
   {
       [Key]
       [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
       public int treatmentID { get; set; }

       [Required(ErrorMessage="Please enter Treatment name")]
       [Display(Name = "Treatment name")]
       public string treatmentName { get; set; }

       [Required(ErrorMessage = "Please enter Treatment cost")]
       [Display(Name = "Treatment cost")]
       [DataType(DataType.Currency)]
       public double treatmentCost { get; set; }

       [Required(ErrorMessage = "Please enter Treatment duration")]
       [Display(Name = "Treatment duration")]
       public int treatmentDuration { get; set; }

       public bool check { get; set; }

bookingcontroller
public ActionResult MakeBooking(BookingView model)
{
    ViewData["Total"] = _boo.CalcTotalCost(model.cost).ToString(CultureInfo.CurrentCulture);

    treats.Check = treats.Check;
    model.TreatmentName = treats.TreatmentName;
    book.cost = model.cost;
    book.numberOfPeole = model.numberOfPeole;
    book.date = model.date;
    book.location = model.location;

    IEnumerable<TreatmentView> treatmentes = new List<TreatmentView>();

    model.Treatmentses= (List<TreatmentView>) treatmentBusiness.GetAllTreatments();

    return View(model);
}

bookingbusiness method cost in the the businesslogic
public double CalcTotalCost(double Cost)
       {
           var bv = new BookingView();

           Cost = 0.00;


           for (var i = 0; i < bv.Treatmentses.Count; i++)
           {
               if (bv.Treatmentses[i].treatmentName == "true")
               {
                   Cost += bv.treatmentCost;
               }
           }

           return Cost;
       }
finally the view of the makebooking
@using System.Collections
@using System.Text
@using Physiq.Data
@using Physiq.Model
@model Physiq.Model.BookingView


@{
    ViewBag.Title = "MakeBooking";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>MakeBooking</h2>
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>MakeBooking</h4>
        <hr/>
        @for(var i=0;i<Model.Treatmentses.Count();i++)
        {
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.CheckBox(@Model.Treatmentses[i].treatmentName)@Model.Treatmentses[i].treatmentName
                
            </div>
        }
        <div class="form-group">
            @Html.LabelFor(model => model.date, htmlAttributes: new {@class = "control-label col-md-2"})
            <div class="col-md-10">
                @Html.EditorFor(model => model.date, new {htmlAttributes = new {@class = "form-control"}})
                @Html.ValidationMessageFor(model => model.date, "", new {@class = "text-danger"})
            </div>
        </div>
       
        <div class="form-group">
            @Html.LabelFor(model => model.location, htmlAttributes: new {@class = "control-label col-md-2"})
            <div class="col-md-10">
                @Html.EditorFor(model => model.location, new {htmlAttributes = new {@class = "form-control"}})
                @Html.ValidationMessageFor(model => model.location, "", new {@class = "text-danger"})
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.numberOfPeole, htmlAttributes: new {@class = "control-label col-md-2"})
            <div class="col-md-10">
                @Html.EditorFor(model => model.numberOfPeole, new {htmlAttributes = new {@class = "form-control"}})
                @Html.ValidationMessageFor(model => model.numberOfPeole, "", new {@class = "text-danger"})
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.cost, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.cost, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.cost, "", new { @class = "text-danger" })
            </div>
        </div>


    <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <span class="glyphicon glyphicon-save" aria-hidden="true"></span>
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
    
    @Html.Label((string) @ViewData["Total"])
}

this is the error that comes up on the browser.but when i comment out my for loop in the business logic method the view displays the checkboxes with the view names along side them.but getting the display of the sum of the checked checkboxes is a problem


any kind of direction or help will be appreciated my email is minenhlegcabashe@gmail.com
Posted
Comments
Mostafa Asaduzzaman 1-Jun-15 20:24pm    
"this is the error that comes up on the browser" what is the error you haven't mentioned it.
--MA

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