Click here to Skip to main content
15,884,041 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Question[VB.NET 2008] DataSet and XML files Pin
steve_949661313-Dec-12 0:06
professionalsteve_949661313-Dec-12 0:06 
AnswerRe: [VB.NET 2008] DataSet and XML files Pin
Eddy Vluggen13-Dec-12 4:28
professionalEddy Vluggen13-Dec-12 4:28 
GeneralRe: [VB.NET 2008] DataSet and XML files Pin
steve_949661313-Dec-12 21:21
professionalsteve_949661313-Dec-12 21:21 
GeneralRe: [VB.NET 2008] DataSet and XML files Pin
Eddy Vluggen14-Dec-12 0:34
professionalEddy Vluggen14-Dec-12 0:34 
QuestionAssembly with different .NET framework versions Pin
marca29212-Dec-12 10:05
marca29212-Dec-12 10:05 
AnswerRe: Assembly with different .NET framework versions Pin
Gerry Schmitz12-Dec-12 12:25
mveGerry Schmitz12-Dec-12 12:25 
QuestionUse A Cookie To Send PersonID To Different Page Pin
xnaLearner12-Dec-12 4:33
xnaLearner12-Dec-12 4:33 
Questiondont allow user to select existing date Pin
xnaLearner10-Dec-12 5:46
xnaLearner10-Dec-12 5:46 
So the user selects holidays (start and end dates) from two calendars, the dates from start to end are then stored in the DB in separate records per date.

(thanks to help from a previous question this all works fine)

Now, I want some sort of error message which doesnt allow the button to be clicked if the dates the user are selecting already exist in the DB.

Im unsure if this is done from the view, or controller?

View:

HTML
<form action ="ListHolidays" id="listHolidays" method="post">
@using (Html.BeginForm()) {
      @Html.ValidationSummary(true)
    <fieldset>
        <legend>Holiday</legend>

        <div>
            @Html.LabelFor(model => model.PersonId, "Person")
        </div>

        <div>     
            @Html.DropDownListFor(model => model.PersonId,
                                new SelectList(ViewBag.Id, "Value", "Text"),
                                "---Select---"
                                )   
         @Html.ValidationMessageFor(model => model.PersonId)            
        </div>

        <div>
            @Html.LabelFor(model => model.HolidayDate)
        </div>

        <div>

            @Html.TextBoxFor(model => model.HolidayDate)

            @Html.TextBoxFor(model => model.endDate)
    <script>

//        Date.format = 'dd/m/yyy';
        $("#HolidayDate").addClass('date-pick');
        $("#endDate").addClass('date-pick');
            //$('.date-pick').datePicker//({dateFormat: 'dd-mm-yy'}).val();

//        clickInput: true

        $(function () {
        //3 methods below dont allow user to select weekends
            $('.date-pick').datePicker(
               {
                   createButton: false,
                   renderCallback: function ($td, thisDate, month, year) 
                   {
                       if (thisDate.isWeekend()) 
                       {
                           $td.addClass('weekend');
                           $td.addClass('disabled');
                       }
                   }
               }
        )

        .bind('click',
            function () 
            {
                $(this).dpDisplay();
                this.blur();
                return false;
            }
        )

        .bind('dateSelected',
            function (e, selectedDate, $td) 
            {
                console.log('You selected ' + selectedDate);
            }
        );

//        HolidayDate is start date
            $('#HolidayDate').bind('dpClosed',
                    function (e, selectedDates) 
                    {
                        var d = selectedDates[0];
                        if (d) 
                        {
                            d = new Date(d);
                            $('#endDate').dpSetStartDate(d.addDays(1).asString());
                        }
                    }
            );

            //end date is end date
            $('#endDate').bind('dpClosed',
                    function (e, selectedDates) 
                    {
                        var d = selectedDates[0];
                        if (d) 
                        {
                            d = new Date(d);
                            $('#HolidayDate').dpSetEndDate(d.addDays(-1).asString());
                        }
                    }
                );
        });



    </script>

     @Html.ValidationMessageFor(model => model.HolidayDate)
        </div>

        <p>
            <input type="submit" value="Create"/>
        </p>


controller:

C#
HttpPost] public ActionResult listHolidays(Holiday holiday, int? PersonId, string HolidayDate, string endDate) {

            DateTime startDates = Convert.ToDateTime(HolidayDate),
                     endDates = Convert.ToDateTime(endDate);

            while (startDates <= endDates)
            {
                if (startDates.DayOfWeek != DayOfWeek.Saturday && startDates.DayOfWeek != DayOfWeek.Sunday)
                {
                    Holiday holiday1 = new Holiday();
                    holiday1.PersonId = PersonId.Value;
                    holiday1.HolidayDate = startDates;

                    db.Holidays.AddObject(holiday1);
                    db.SaveChanges();



                    //say start date is 10. AddDays(1) will make it 11 then return it to startDates in 'startDates' = startdates,
                    //but doesnt chage the value of startdates = 'startdates'
                }

                startDates = startDates.AddDays(1);
            }

            return RedirectToAction("Index");


so...? if holidayDate = db.exisitng date?

Unsure how to go about this.

Please advise.

thanks
AnswerRe: dont allow user to select existing date Pin
Pete O'Hanlon10-Dec-12 5:53
mvePete O'Hanlon10-Dec-12 5:53 
GeneralRe: dont allow user to select existing date Pin
xnaLearner10-Dec-12 6:23
xnaLearner10-Dec-12 6:23 
GeneralRe: dont allow user to select existing date Pin
xnaLearner10-Dec-12 23:26
xnaLearner10-Dec-12 23:26 
GeneralRe: dont allow user to select existing date Pin
Pete O'Hanlon10-Dec-12 23:32
mvePete O'Hanlon10-Dec-12 23:32 
GeneralRe: dont allow user to select existing date Pin
xnaLearner10-Dec-12 23:46
xnaLearner10-Dec-12 23:46 
GeneralRe: dont allow user to select existing date Pin
Pete O'Hanlon10-Dec-12 23:51
mvePete O'Hanlon10-Dec-12 23:51 
GeneralRe: dont allow user to select existing date Pin
xnaLearner11-Dec-12 0:21
xnaLearner11-Dec-12 0:21 
GeneralRe: dont allow user to select existing date Pin
Pete O'Hanlon11-Dec-12 1:02
mvePete O'Hanlon11-Dec-12 1:02 
QuestionRun through loop for week and dont select weekends Pin
xnaLearner10-Dec-12 4:13
xnaLearner10-Dec-12 4:13 
AnswerRe: Run through loop for week and dont select weekends Pin
Pete O'Hanlon10-Dec-12 4:31
mvePete O'Hanlon10-Dec-12 4:31 
GeneralRe: Run through loop for week and dont select weekends Pin
xnaLearner10-Dec-12 4:52
xnaLearner10-Dec-12 4:52 
GeneralRe: Run through loop for week and dont select weekends Pin
Pete O'Hanlon10-Dec-12 4:53
mvePete O'Hanlon10-Dec-12 4:53 
QuestionDeploying a Windows Service Pin
indian14310-Dec-12 4:09
indian14310-Dec-12 4:09 
AnswerRe: Deploying a Windows Service Pin
Pete O'Hanlon10-Dec-12 5:04
mvePete O'Hanlon10-Dec-12 5:04 
GeneralRe: Deploying a Windows Service Pin
indian14310-Dec-12 5:08
indian14310-Dec-12 5:08 
GeneralRe: Deploying a Windows Service Pin
Pete O'Hanlon10-Dec-12 5:20
mvePete O'Hanlon10-Dec-12 5:20 
Questionrun through startDate to endDate and add each record to DB Pin
xnaLearner10-Dec-12 2:04
xnaLearner10-Dec-12 2:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.