Nov 4, 2014

Custom Helpers in Asp.net MVC

http://www.codeproject.com/Tips/832640/Custom-Helpers-in-Asp-net-MVC

May 20, 2014

List

Data Structure 
  1. IEnumerable
  2. IQueryable
  3. Dictionary and IDictionary
  4. ICollection
  5. HashTable
  6. IList or List


Operation 

Algorithm = > Operation

http://auk-port.blogspot.com/2012/08/difference-among-ienumerable-iqueryable_5620.html

http://people.cs.aau.dk/~normark/oop-csharp/html/notes/collections_themes-list-sect.html

http://www.dotnet-tricks.com/Tutorial/linq/I8SY160612-IEnumerable-VS-IQueryable.html

May 19, 2014

MVC Unit Testing

http://www.codeproject.com/Articles/763928/MVC-Unit-Testing-Unleashed#BasicexampleofUnitTesting
http://www.codeproject.com/Articles/763928/MVC-Unit-Testing-Unleashed




namespace MyMathsLibrary
{
    public class CustomMaths
    {
        public int Number1 { get; set; }
        public int Number2 { get; set; }

        public CustomMaths(int num1, int num2)
        {
            Number1 = num1;
            Number2 = num2;
        }
        public int Add()
        {
            return Number1 + Number2;
        }      
    }
}


**********************UnitTest****************
namespace MathsTest
{
[TestClass]
public class TestMathsClass
{
    [TestMethod]
    public void TestAdd()
    {
        //Arrange
        CustomMaths maths = new CustomMaths(6, 5);

        //Act
        int result = maths.Add();

        //Assert
        Assert.AreEqual<int>(11, result);
    }
}
}

May 17, 2014

C#

Timer

Timer Example ; Auto  Fire after 3 seconds...........................

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text;
using System.Timers;

namespace WindowsFormsApplication1
{
  
    public partial class Form1 : Form
    {
       private System.Timers.Timer timer;
       private int counter = 0;

       public Form1()
       {
        
           InitializeComponent();
           timer = new System.Timers.Timer();
           timer.Elapsed += timer_Elapsed;
           timer.Interval = (1000 * 3);
           timer.Start();
       }
       void timer_Elapsed(object sender, ElapsedEventArgs e)
       {
           counter = counter + 1;
       
               timer.Stop();
             MessageBox.Show(counter.ToString());
               timer.Start();
         
       }
    }
}
http://www.codeproject.com/Tips/480049/Shut-Down-Restart-Log-off-or-Lock-your-computer-in

SOLID


May 14, 2014

MVC Different Redirection Techniques (Razor)


MVC4 Different Redirection Techniques (Razor)

This tip lists different redirection techniques for MVC4.
  1. HTML Tag
    <input type="button" value="Forgot Password" 
    onclick="window.location.href('@Url.Action("ForgotPassword","Account")')" />
       
  2. For posting, you could use a form:
    <form method="post" id="signin" action="@Url.Action("ForgotPassword", "Account")">
    <input type="button" value="Forgot Password" />
    </form>
       
  3. Using script:
    <script type="text/javascript">
        $(document).ready(function () {     
          $('#btnForgotPassword').click(function (e)      {
              location.href = '@Url.Content("~/Account/ForgotPassword/")';
          });
        });
    </script>
    //change below input tag
    <input id='btnForgotPassword' type="button" value="Forgot Password" />
       
  4. If it is a link:
    @Html.ActionLink("some text", "actionName", "controllerName")
       
  5. For posting, use a form:
    @ using(Html.BeginForm("actionName", "controllerName")) { 
        <input type="submit" value="Some text" />
    }
       
  6. For Anchor Tag:
    <a href="http://www.codeproject.com/Controller/View" class="Button">Text</a>
       
  7. Using RenderAction:
    @{ Html.RenderAction("ActionName", "ControllerName", 
    new { FranchiseSetId = Model.FranchiseSetID }); }
      

 

http://www.codeproject.com/Tips/583469/MVC-Different-Redirection-Techniques-Razor

May 13, 2014

ASP.Net MVC HTML Helper

<table>        
     <tr>
        <td>
            <span>Account Type Name</span>          
        </td>
        <td>
         @Html.DropDownListFor(model => model.AccountTypeId, new SelectList( ViewBag.AccountTypes, "value", "text"))
         
        </td>
    </tr>
</table>


 public ActionResult AddEditView(string accountSubTypeID)
        {
            AccountSubTypeModel accountSubTypeModel = new AccountSubTypeModel();
            if (!string.IsNullOrEmpty(accountSubTypeID))
            {
                accountSubTypeModel = _subTypeService.SingleOrDefault(new Guid(accountSubTypeID));
            }
           this.LoadDDL(accountSubTypeModel);
            return PartialView(accountSubTypeModel);
        }



private void LoadDDL(AccountSubTypeModel accountSubTypeModel)
        {
            var accountTypes = _typeService.GetDropDownData("Id", "TypeName");
            var selectList = new SelectList(accountTypes, "Value", "Text", accountSubTypeModel.AccountTypeId);
            ViewBag.AccountTypes = selectList;
        }   

May 9, 2014

Data Path TPAWeb MVC

http://mvcpaging.apphb.com/AreaOne/Home

Tools>Extensions and Updates>

PM> Install-Package MVC4.Paging

bootstrap-modal

http://jschr.github.io/bootstrap-modal/
http://www.codeproject.com/Tips/597253/Using-the-Grid-MVC-in-ASP-NET-MVC
https://gridmvc.codeplex.com/SourceControl/latest#GridMvc/GridMvc/Pagination/GridPager.cs


Ctrl + Alt + i = Immediate Window to view cshtml value
*******************************************************************************
if database Change occured:
1.Database.tt
2.Generate.tt
3.show all files
4.Include all hidden Files
5.Rebuild
6.Commit
DELETE FROM FOLLOWING FILES:

D:\User\Rubol\Projects\TPAManagerMVC\July.TPAManager\July.TPAManager\TPAWeb.2013\July.Project\IOC\Core\ProjectServiceModule.cs
D:\User\Rubol\Projects\TPAManagerMVC\July.TPAManager\July.TPAManager\TPAWeb.2013\July.Project\IOC\Core\ProjectRepositoryModule.cs
Domain => Model
Repository
*****************************************************************************

\July.TPAManager\TPAWeb.2013\July.Common\Partial\PartialDomainModel\PersonModel.partial.cs
\July.TPAManager\TPAWeb.2013\July.Common\Partial\PartialViewModel\PhoneViewModel.partial.cs
\July.TPAManager\TPAWeb.2013\July.Common\Models\Partial\Person.partial.cs

Viva



 CeFALO

 oop , patterns, web service, C#, analytical skill
asp.net 

May 6, 2014

Entity Framework in an ASP.NET MVC

http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
http://blog.longle.net/2013/05/11/genericizing-the-unit-of-work-pattern-repository-pattern-with-entity-framework-in-mvc/
http://csharppulse.blogspot.com/2013/09/learning-mvc-part-6-generic-repository.html

Repository Pattern in MVC5

http://code.msdn.microsoft.com/Repository-Pattern-in-MVC5-0bf41cd0
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

May 5, 2014

C# ASP.Net EDMX

Load DropdownList
 <asp:DropDownList ID="ddlState" runat="server"  CssClass="dropdown"/> 
if (!Page.IsPostBack)
            {
                this.LoadState();
              }

private void LoadState()
        {
            UserBO userBO = new UserBO();
            ddlState.DataSource = userBO.GetStateName();
            ddlState.DataValueField = "State1";
            ddlState.DataTextField = "State1";
            ddlState.DataBind();
        }
 public List<State> GetStateName()
        {
            using (dbcntx = new FiduciaryKEntities())
            {
                return dbcntx.States.ToList();
            }
        }



Load Form Data

 if (Request.QueryString["userId"] != null)
                {
                    UserBO userBO = new UserBO();
                    int userId = int.Parse(Request.QueryString["userId"]);                  
                    this.LoadUser(userId);
                 
                }
 private void LoadUser(int uId)
        {

            UserBO userBO = new UserBO();
            FiduciaryK_User objUser = userBO.GetUserById(uId);
            if (objUser != null)
            {
                ddlTitle.Text = objUser.Title;
                txtFirstName.Value = objUser.FirstName;
                txtLastName.Value = objUser.LastName;              
                ddlState.SelectedValue= objUser.State;
             }
        }

Form
        <input type="text" class="validate[required]" value="" id="txtFirstName" runat="server" /><strong>*</strong></li>

          <asp:DropDownList ID="ddlState" runat="server"  CssClass="dropdown"/>         


Load DropDownList
                        <li class="clearfix">
                                    <label>Title:</label>
                                    <asp:DropDownList ID="ddlTitle" runat="server">
                                        <asp:ListItem></asp:ListItem>
                                        <asp:ListItem>Mr.</asp:ListItem>
                                        <asp:ListItem>Miss</asp:ListItem>
                                        <asp:ListItem>Mrs.</asp:ListItem>
                                        <asp:ListItem>Ms.</asp:ListItem>
                                    </asp:DropDownList>
                                </li>

Save 

protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                userBO = new UserBO();
                user.Title = ddlTitle.SelectedItem.Text;
                user.FirstName = txtFirstName.Value.Trim();
                user.LastName = txtLastName.Value.Trim();          
                 user.State = ddlState.SelectedItem.Text;          
                user.Email = txtEmail.Value.Trim();
                if (!string.IsNullOrEmpty(txtEmail.Value))
                {
                    if (userBO.CheckEmailExist(txtEmail.Value.Trim()) == true)
                    {
                        this.lblerror.Text = "Account already exists for this email!";
                        return;
                    };

                }
            if (!string.IsNullOrEmpty(txtReferralCode.Value))
                {
                    user.ReferralId = SaveReferral(txtReferralCode.Value);
                }
            Guid registercode = Guid.NewGuid();
             user.VerificationCode = registercode;
             user.IsActive = true;
             userBO.SaveUserInfo(user);

                this.SendMail(user.ReferralId == null ? 0 : user.ReferralId.Value, registercode,                             txtUserName.Value.Trim(), txtFirstName.Value.Trim(), txtEmail.Value.Trim());

                Response.Redirect("../Account/Login.aspx");

            }
            catch (Exception ex)
            { }
            finally
            { }
        }
Edit
protected void btnSubmit_Click(object sender, EventArgs e)
        {

            UserBO userBO = new UserBO();
            try
            {
                if (Request.QueryString["userId"] !=null)
                {
                    int userId = Convert.ToInt32(Request.QueryString["userId"]);
                    objUser = new FiduciaryK_User();
                    objUser = userBO.GetUserById(userId);

                    objUser.Title = ddlTitle.SelectedValue;
                    objUser.FirstName = txtFirstName.Value.Trim();
                    objUser.LastName = txtLastName.Value.Trim();
                    objUser.Address1 = txtAdd.Value;
                    objUser.City = txtCity.Value.Trim();

                    objUser.State = ddlState.SelectedValue;
                    userBO.SaveUserInfo(objUser);
                    Session["FirstName"] = txtFirstName.Value.Trim();
               }
            }
            catch (Exception ex)
            {
            }


 public void SaveUserInfo(FiduciaryK_User user)
        {
            try
            {
                if (user.Id == 0)
                {
                    dbcntx.FiduciaryK_User.Add(user);
                }
                dbcntx.SaveChanges();
            }
            catch (Exception ex)
            { }
            finally
            {
            }
        }

 public FiduciaryK_User GetUserById(int userid)
        {        
            return dbcntx.FiduciaryK_User.Where(u => u.Id == userid).FirstOrDefault();
        }

 public Boolean CheckEmailExist(string email)
        {
            try
            {
                if (dbcntx.FiduciaryK_User.Count(x => x.Email.Trim() == email) > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
        }



   private void SendMail(int refId, Guid registercode, string userName,string firstName, string emailto)
        {
                       this.SendInternalEmail();                                     
        }

private void SendInternalEmail()
        {
         
            string to = "adrienne@redhawkwa.com,rick@redhawkwa.com,internalsales@julyservices.com";
            string cc = "gsnyder@julyservices.com,mahfuz@julyservices.com";
            string subject = "Fiduciaryk – Registration Request";
            string name = txtFirstName.Value.Trim() + " " + txtLastName.Value.Trim();
         
            string body = "<style>img{border: none; display:block;}</style><table style='background:#FAFAFA; border: 1px solid #990000; border-top: 30px solid #990000; border-bottom: 30px solid #990000;'><tr><td colspan='3' style='height:20px;'></td></tr><tr><td width='20'>&nbsp;</td><td><img src='https://fiduciaryk.com/Content/images/logo.png' width='387' height='100' alt='FiduciaryK Logo' /></td></tr><tr><td colspan='3' style='height:20px;'></td></tr><tr><td width='20'>&nbsp;</td><td style='font-family:Arial; font-size:14px; line-height:20px; color:#333333;'>Registration Request:</BR>Name: " + name + "</BR>Email: " + txtEmail.Value.Trim() + "</BR>Phone: " + txtPhone.Value.Trim() + "</td><td width='20'>&nbsp;</td></td><tr><td colspan='3' style='height:30px;'></td></tr></table>";
            email.SendEmailAsyn(ContactEmails, to, cc, subject, body);

        }
Send Mail
public void SendEmailAsyn(string mailFrom, string mailTo,string mailCC, string subject, string body)
        {
            try
            {
                if (mailTo.Trim() != "" && mailTo.Trim() != "&nbsp;")
                {
                    if (isEmail(mailTo))
                    {
                        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

                        message.From = new MailAddress(mailFrom);
                        var mailTos = mailTo.Split(new Char[] { ',', ';' });
                        foreach (var to in mailTos)
                        {
                            if (!String.IsNullOrEmpty(to))
                                message.To.Add(new MailAddress(to));
                        }
                        var mailCCs = mailCC.Split(',');
                        foreach (var cc in mailCCs)
                        {
                            if (!String.IsNullOrEmpty(cc))                              
                            message.CC.Add(new MailAddress(cc));
                        }
                       
                        message.Subject = subject;
                        message.Body = body;

                        message.Priority = System.Net.Mail.MailPriority.Normal;
                        message.IsBodyHtml = true;


                        System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
                        smtpClient.Host = "mail.julyservices.com";
                        System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("dp_smtp", "Dp$123456", "julyservices");
                        smtpClient.Credentials = SMTPUserInfo;
                        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                        smtpClient.Send(message);
                    }
                }
            }
            catch (Exception ex)
            {

            }

        }


 public bool isEmail(string inputEmail)
        {
            var mails = inputEmail.Split(new Char[] { ',', ';' });

            //inputEmail = NulltoString(inputEmail);
            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                  @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                  @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);

            Boolean isValidMail = false;

            foreach (var mail in mails)
            {
                if (!String.IsNullOrEmpty(mail))
                {
                    if (re.IsMatch(mail))
                    {
                        isValidMail = true;
                    }
                    else
                    {
                        isValidMail = false;
                        break;
                    }
                }
            }

            return isValidMail;
        }

Download Excel Template
<div class="dwnld-excel">
                            <asp:LinkButton CssClass="downloadlink" ID="censusFileDlLink" runat="server" OnClick="downloadSampleCensusFile">Download Excel Template</asp:LinkButton>
                        </div>
protected void downloadSampleCensusFile(object sender, EventArgs e)
        {
            string fileName = "Census-Spreadsheet.xls";
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
            filePath = Server.MapPath("/Documents/" + fileName);
            Response.TransmitFile(filePath);
            Response.End();
        }
****************************************************

Apr 21, 2014

ASP.NET

grouping in an ASP.Net GridView
http://www.c-sharpcorner.com/uploadfile/e06010/grouping-in-asp-net-gridview/


<asp:RadioButtonList ID="rdoPlanExist" CssClass="plan-chooser" runat="server"                                         RepeatDirection="Horizontal">
                            <asp:ListItem Value="0" Selected="True">New Plan</asp:ListItem>
                            <asp:ListItem Value="1">Existing Plan </asp:ListItem>
 </asp:RadioButtonList>


  proposal.IsExisting = rdoPlanExist.SelectedItem.Value == "0" ? false : true;
                    if (proposal.IsExisting.Value)
                    {
                        proposal.PlanAsset = txtAssets.Text == "" ? 0 : decimal.Parse(txtAssets.Text);                    
                        proposal.NumberOfParticipant = txtParticipants.Text == "" ? 0 :                        int.Parse(txtParticipants.Text);
                        proposal.Recordkeeper = txtRecordkeeper.Text;                
                        proposal.PlanType = int.Parse(ddlPlanType.SelectedValue);
                    }

Apr 8, 2014

URL

Live Project
https://fiduciaryk.com/

ASP.NET

Multilevel Nested Master/Detail Data Display Using GridView

http://www.codeproject.com/Articles/14861/Multilevel-Nested-Master-Detail-Data-Display-Using

jQuery 
http://www.webcoachbd.com/jquery-tutorials/jquery-ajax
Validation

http://www.codeproject.com/Articles/866370/Beginners-guide-on-jQuery-Selectors
http://posabsolute.github.io/jQuery-Validation-Engine/

Class and fill ,Group By
http://msdn.microsoft.com/en-us/library/bb545971.aspx


Complete Bangla Quran Translation

http://ebookbd.info/complete-bangla-quran-translation-free-download.html
http://www.searchtruth.com/arabic/lessons/unit1_writing.php

Mar 31, 2014

SP Function C#.Net




public DataTable GetFeeDiscloseRecurringFees(string planNumber)
         {
             dtData = new DataTable();
             string query;
             try
             {
                 query = "pr_GetFeeDiscloseRecurringFees";
                 this.DataContext.Connect();
                 this.DataContext.Connection.RefeshParameters();
this.DataContext.Connection.AddParameter("@PlanNumber", _JULY_Library.clsConnection.enmDbType.Integer, planNumber);
dtData = this.DataContext.Connection.GetDataTable(query, CommandType.StoredProcedure, ""true);
                 return dtData;
             }
             catch (Exception ex)
             {
                 throw ex;
             }
         }



USE [TPAManager_be]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROC [dbo].[pr_GetFeeDiscloseRecurringFees]
@PlanNumber int
AS
SET NOCOUNT ON

Select Payee as provider, ServiceType, PaymentMethod, PaymentInterval, FeeName
, Case when [AmountType]='Percent' then dbo.fnFormatPercentage([FeeAmount], NoOfDecimals)
ELSE dbo.fnFormatCurrency([FeeAmount],NoOfDecimals) END AS AnnualFeeAmount
, DBO.fnFormatWithUnitTypeInputMast(ISNULL([Quantity], 0), [UnitTypeInputMask],0) AS CurrentQuantity
--Case when FeeID in(22,86) then 0 Else NoOfDecimals End) AS CurrentQuantity
, dbo.fnFormatCurrency([AnnualFee],0) AS ProjectedAnnualFee
--Case when FeeID in(22,86) then 0 Else NoOfDecimals End) AS ProjectedAnnualFee
from vw_FeeDisclosureRecurringFeeDetails
WHERE PlanNumber  = @PlanNumber
ORDER BY SequenceNumber

ALTER FUNCTION [dbo].[fnFormatWithUnitTypeInputMast] (@value Decimal(24, 7), @UnitTypeInputMask varchar(50), @NumberOfDecimals int)
RETURNS VARCHAR(32)
AS
BEGIN
DECLARE @temp varchar(38)
SET @value = ISNULL(@value, 0)
IF @UnitTypeInputMask = 'Currency'
                SET @temp = DBO.fnFormatCurrency(@Value, @NumberOfDecimals)
ELSE
                SET @temp = DBO.fnFormatDecimal(@Value, CAST(@UnitTypeInputMask as Int))

RETURN @temp
END


ALTER FUNCTION [dbo].[fnFormatCurrency] (@value Decimal(24, 7), @NumberOfDecimals int)
RETURNS VARCHAR(32)
AS
BEGIN
                DECLARE @temp varchar(38),
                                                @NegYN BIT
               
                SET @value = ISNULL(@value, 0.00)

                IF @value < 0.00
                BEGIN
                                SET @NegYN = 1
                                SET @value = ABS(@VALUE)
                END
                ELSE
                BEGIN
                                SET @NegYN = 0
                END

                IF @NumberOfDecimals > 0
                BEGIN
                                SET @temp = PARSENAME(Convert(varchar,Convert(money,@value),1),2)
                                SET @temp = @temp + RIGHT(str(@value, 32, @NumberOfDecimals) , @NumberOfDecimals + 1)
                END
                ELSE
                BEGIN
                                SET @temp = PARSENAME(Convert(varchar,Convert(money,cast(round(@Value, 0) as bigint)),1),2)
                END
               
                if @NegYN = 1
                                SET @temp = '($' + @temp + ')'
                ELSE
                                SET @temp = '$' + @temp

                RETURN @temp
END