Click here to Skip to main content
12,693,601 members (27,779 online)

.NET Framework

 
AnswerRe: pulling across value from list to display in view Pin
xnaLearner14-Dec-12 7:49
memberxnaLearner14-Dec-12 7:49 
AnswerRe: pulling across value from list to display in view Pin
frazzle-me14-Dec-12 18:41
memberfrazzle-me14-Dec-12 18:41 
GeneralRe: pulling across value from list to display in view Pin
xnaLearner15-Dec-12 9:28
memberxnaLearner15-Dec-12 9:28 
Questionproblem with relationships Pin
xnaLearner13-Dec-12 3:45
memberxnaLearner13-Dec-12 3:45 
AnswerRe: problem with relationships Pin
Richard Deeming13-Dec-12 4:48
memberRichard Deeming13-Dec-12 4:48 
GeneralRe: problem with relationships Pin
xnaLearner13-Dec-12 5:37
memberxnaLearner13-Dec-12 5:37 
Question[VB.NET 2008] DataSet and XML files Pin
steve_949661313-Dec-12 1:06
membersteve_949661313-Dec-12 1:06 
AnswerRe: [VB.NET 2008] DataSet and XML files Pin
Eddy Vluggen13-Dec-12 5:28
memberEddy Vluggen13-Dec-12 5:28 
GeneralRe: [VB.NET 2008] DataSet and XML files Pin
steve_949661313-Dec-12 22:21
membersteve_949661313-Dec-12 22:21 
GeneralRe: [VB.NET 2008] DataSet and XML files Pin
Eddy Vluggen14-Dec-12 1:34
memberEddy Vluggen14-Dec-12 1:34 
QuestionAssembly with different .NET framework versions Pin
marca29212-Dec-12 11:05
membermarca29212-Dec-12 11:05 
AnswerRe: Assembly with different .NET framework versions Pin
Gerry Schmitz12-Dec-12 13:25
memberGerry Schmitz12-Dec-12 13:25 
QuestionUse A Cookie To Send PersonID To Different Page Pin
xnaLearner12-Dec-12 5:33
memberxnaLearner12-Dec-12 5:33 
Questiondont allow user to select existing date Pin
xnaLearner10-Dec-12 6:46
memberxnaLearner10-Dec-12 6: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:

<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:

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 6:53
protectorPete O'Hanlon10-Dec-12 6:53 
GeneralRe: dont allow user to select existing date Pin
xnaLearner10-Dec-12 7:23
memberxnaLearner10-Dec-12 7:23 
GeneralRe: dont allow user to select existing date Pin
xnaLearner11-Dec-12 0:26
memberxnaLearner11-Dec-12 0:26 
GeneralRe: dont allow user to select existing date Pin
Pete O'Hanlon11-Dec-12 0:32
protectorPete O'Hanlon11-Dec-12 0:32 
GeneralRe: dont allow user to select existing date Pin
xnaLearner11-Dec-12 0:46
memberxnaLearner11-Dec-12 0:46 
GeneralRe: dont allow user to select existing date Pin
Pete O'Hanlon11-Dec-12 0:51
protectorPete O'Hanlon11-Dec-12 0:51 
GeneralRe: dont allow user to select existing date Pin
xnaLearner11-Dec-12 1:21
memberxnaLearner11-Dec-12 1:21 
GeneralRe: dont allow user to select existing date Pin
Pete O'Hanlon11-Dec-12 2:02
protectorPete O'Hanlon11-Dec-12 2:02 
QuestionRun through loop for week and dont select weekends Pin
xnaLearner10-Dec-12 5:13
memberxnaLearner10-Dec-12 5:13 
AnswerRe: Run through loop for week and dont select weekends Pin
Pete O'Hanlon10-Dec-12 5:31
protectorPete O'Hanlon10-Dec-12 5:31 
GeneralRe: Run through loop for week and dont select weekends Pin
xnaLearner10-Dec-12 5:52
memberxnaLearner10-Dec-12 5:52 
GeneralRe: Run through loop for week and dont select weekends Pin
Pete O'Hanlon10-Dec-12 5:53
protectorPete O'Hanlon10-Dec-12 5:53 
QuestionDeploying a Windows Service Pin
indian14310-Dec-12 5:09
memberindian14310-Dec-12 5:09 
AnswerRe: Deploying a Windows Service Pin
Pete O'Hanlon10-Dec-12 6:04
protectorPete O'Hanlon10-Dec-12 6:04 
GeneralRe: Deploying a Windows Service Pin
indian14310-Dec-12 6:08
memberindian14310-Dec-12 6:08 
GeneralRe: Deploying a Windows Service Pin
Pete O'Hanlon10-Dec-12 6:20
protectorPete O'Hanlon10-Dec-12 6:20 
Questionrun through startDate to endDate and add each record to DB Pin
xnaLearner10-Dec-12 3:04
memberxnaLearner10-Dec-12 3:04 
AnswerRe: run through startDate to endDate and add each record to DB Pin
xnaLearner10-Dec-12 3:35
memberxnaLearner10-Dec-12 3:35 
QuestionASP.NET Post Textbox After Button Click Pin
xnaLearner9-Dec-12 12:15
memberxnaLearner9-Dec-12 12:15 
AnswerRe: ASP.NET Post Textbox After Button Click Pin
Richard MacCutchan9-Dec-12 22:54
mvpRichard MacCutchan9-Dec-12 22:54 
GeneralRe: ASP.NET Post Textbox After Button Click Pin
xnaLearner10-Dec-12 1:14
memberxnaLearner10-Dec-12 1:14 
Question.netframework Pin
zofi518-Dec-12 5:30
memberzofi518-Dec-12 5:30 
AnswerRe: .netframework Pin
Dave Kreskowiak8-Dec-12 7:37
mvpDave Kreskowiak8-Dec-12 7:37 
AnswerRe: .netframework Pin
Eddy Vluggen8-Dec-12 8:18
memberEddy Vluggen8-Dec-12 8:18 
GeneralRe: .netframework Pin
Kevin Bewley14-Jan-13 0:46
memberKevin Bewley14-Jan-13 0:46 
AnswerRe: .netframework Pin
jibesh11-Dec-12 11:36
memberjibesh11-Dec-12 11:36 
QuestionEnter 3 dates and display order in different VIEW, after click Pin
xnaLearner7-Dec-12 10:52
memberxnaLearner7-Dec-12 10:52 
Question[VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) Pin
steve_94966136-Dec-12 22:37
membersteve_94966136-Dec-12 22:37 
AnswerRe: [VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) Pin
Zaf Khan10-Dec-12 18:57
memberZaf Khan10-Dec-12 18:57 
GeneralRe: [VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) Pin
steve_949661311-Dec-12 22:20
membersteve_949661311-Dec-12 22:20 
GeneralRe: [VB.NET 2008] How to detect if a page of a TabControl is selected (Windows CE) Pin
Zaf Khan12-Dec-12 3:13
memberZaf Khan12-Dec-12 3:13 
Question[VB.NET 2008] How to get control on objects created at runtime Pin
steve_94966135-Dec-12 5:54
membersteve_94966135-Dec-12 5:54 
AnswerRe: [VB.NET 2008] How to get control on objects created at runtime Pin
Eddy Vluggen5-Dec-12 6:40
memberEddy Vluggen5-Dec-12 6:40 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime Pin
steve_94966135-Dec-12 21:59
membersteve_94966135-Dec-12 21:59 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime Pin
Eddy Vluggen6-Dec-12 3:27
memberEddy Vluggen6-Dec-12 3:27 
GeneralRe: [VB.NET 2008] How to get control on objects created at runtime Pin
steve_94966136-Dec-12 4:26
membersteve_94966136-Dec-12 4:26 

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.


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 17 Jan 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid