NW Web Designs

... keeping it simple

5. August 2014 15:19
by Greg
0 Comments

Checking for a duplicate name with Linq

5. August 2014 15:19 by Greg | 0 Comments

 

        public ActionResult AddNewTearcher(string name)
        {
            var currentUser = (AuthenticatedUser)Session["CurrentUser"];
            var academicYearCode = "2013-14"; //LookupUtil.GetCurrentAcademicYearCode();
            var Results = EducationPersonnelUtil.GetTeacherStatusList(currentUser.ProviderId, academicYearCode, currentUser.UserId);

            var x = Results.Where(n => n.TeacherName == name.ToUpper());

            if (!x.Any())
            {
                var UpDated = new LocalTeachersStatusModel
                {
                    ProviderId = currentUser.ProviderId,
                    AcademicYearCode = academicYearCode,
                    TeacherName = name.ToUpper(),
                    EmpType = 0,
                    Experience = 0,
                    CertNotReported = false,
                    CertAEC = false,
                    CertK12 = false,
                    CertSEC = false,
                    CertTESOL = false
                };


                UpDated.Update(currentUser.UserId);
                return RedirectToAction("LocalTeacherStatus");
            }
            else
            {
                // http://stackoverflow.com/questions/407651/how-do-you-trigger-the-error-callback-in-a-jquery-ajax-call-using-asp-net-mvc
                //return new HttpStatusCodeResult(500, "Duplicate Teacher Name");

                Response.StatusCode = 550;
                Response.Write("Duplicate Teacher Name");
                return new EmptyResult();

            }

11. May 2014 18:30
by Greg
0 Comments

RouteConfig.cs

11. May 2014 18:30 by Greg | 0 Comments

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using System.Web.Routing; 
 
namespace AngularJS_WebApi_EF 
{ 
    public class RouteConfig 
    { 
        public static void RegisterRoutes(RouteCollection routes) 
        { 
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
 
            routes.MapRoute( 
                name: "Default", 
                url: "{controller}/{action}/{id}", 
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
            ); 
        } 
    } 
}

11. May 2014 18:28
by Greg
0 Comments

Route Config

11. May 2014 18:28 by Greg | 0 Comments

   1:  using System; 
   2:  using System.Collections.Generic; 
   3:  using System.Linq; 
   4:  using System.Web; 
   5:  using System.Web.Mvc; 
   6:  using System.Web.Routing; 
   7:   
   8:  namespace AngularJS_WebApi_EF 
   9:  { 
  10:      public class RouteConfig 
  11:      { 
  12:          public static void RegisterRoutes(RouteCollection routes) 
  13:          { 
  14:              routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
  15:   
  16:              routes.MapRoute( 
  17:                  name: "Default", 
  18:                  url: "{controller}/{action}/{id}", 
  19:                  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
  20:              ); 
  21:          } 
  22:      } 
  23:  }

25. April 2014 06:57
by Greg
0 Comments

JQuery Datepicker and Min-max dates

25. April 2014 06:57 by Greg | 0 Comments

jQuery date picker ... setting a minimum and maximum date.

Set a TextBox with a class of datepick:

<asp:TextBox id="txtDate" runat="server" CssClass="datepick">

</asp:TextBox>

jQuery script in head or footer:

<script type="text/javascript">

$(document).ready(function() {

$('input.datepick');

$.ajax({

type: 'POST',

url: 'ClassTestsAdd.aspx/GetMinDate',

contentType: 'application/json; charset=utf-8',

dataType: 'json',

success: function(data) {

var msg = data;

if (msg.hasOwnProperty('d'))

msg = msg.d;

$('input.datepick').datepicker({

maxDate: '0',

minDate: msg,

onSelect: function() {

$("select[tabindex=" + (this.tabIndex + 1) + "]").focus();

}

});

},

error: function(data) {

$('input.datepick').datepicker({

maxDate: '0',

onSelect: function() {

$("select[tabindex=" + (this.tabIndex + 1) + "]").focus();

}

});

}

});

});

</script>

8. January 2013 23:44
by Greg
0 Comments

Custom Validators in Asp.Net C#

8. January 2013 23:44 by Greg | 0 Comments

Your standard Custom Validator:

 

<asp:CustomValidator ID="cvTimeDiff" ValidationGroup="Custom" runat="server"
Display="Dynamic" ErrorMessage="End time should be greater than Start time"
OnServerValidate="CompareTime"></asp:CustomValidator>

 

The attribute "OnServerValidate" is the client-side part of the validator and is what I use by default.
Its value is the name of the server method used to validate something to true or false.

This is the server side code:

 

   protected void CompareTime(object source, ServerValidateEventArgs args)
      {
          *** Do some validation and return the results as boolean b ***
          args.IsValid = b;
      }



Now your ready to fire the custom validator.

First call the validate method:

    Validate("Custom");


Then check if the page is valid and do something:

   if(Page.IsValid)
   {
    Do something when valid
   }

23. December 2012 07:00
by Greg
0 Comments

There is a duplicate ‘system.web.extensions/scripting/scriptResourceHandler’ section defined

23. December 2012 07:00 by Greg | 0 Comments

Lots of things can cause this error to pop-up, but for me it was something very obscure.  I tried everything I could find on the web … then I actually read the compile error.

CVT1108 : cannot open C:/Windows/TEMP/xxx.tmp for writing

So, I went to the ‘Windows\temp’ folder and checked the permissions, and there it was … make sure that the IIS _IUSRS account has read, write and delete rights on the folder. Some how mine disappeared. After I reset them I was back online. How they disappeared I don’t know, but I have a sneaky idea it was the latest update from Microsoft.

23. December 2012 06:59
by Greg
0 Comments

Bin Deploying ASP.NET MVC-3

23. December 2012 06:59 by Greg | 0 Comments

If your server doesn’t have ASP.NET MVC 3 installed, you’ll need to make sure the following set of assemblies are deployed in the bin folder of your web application:

  • Microsoft.Web.Infrastructure.dll
  • System.Web.Helpers.dll
  • System.Web.Mvc.dll
  • System.Web.Razor.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll

23. December 2012 06:54
by Greg
0 Comments

JQuery Datepicker and Min-max dates

23. December 2012 06:54 by Greg | 0 Comments

jQuery date picker ... setting a minimum and maximum date.

Set a TextBox with a class of datepick:

<asp:TextBox id="txtDate" runat="server" CssClass="datepick">
</asp:TextBox>

jQuery script in head or footer:

<script type="text/javascript">
        $(document).ready(function() {
            $('input.datepick');
            $.ajax({
               type: 'POST',
               url: 'ClassTestsAdd.aspx/GetMinDate',
               contentType: 'application/json; charset=utf-8',
               dataType: 'json',
               success: function(data) {
               var msg = data;
               if (msg.hasOwnProperty('d'))
                msg = msg.d;
               $('input.datepick').datepicker({
               maxDate: '0',
               minDate: msg,
               onSelect: function() {
                  $("select[tabindex=" + (this.tabIndex + 1) + "]").focus();
                 }
                });
               },
               error: function(data) {
               $('input.datepick').datepicker({
               maxDate: '0',
               onSelect: function() {
                 $("select[tabindex=" + (this.tabIndex + 1) + "]").focus();
                }
               });
               }
           });
       });
   </script>