Tag Archives: .NET

ASP.NET MVC with models inheritance and views

Hi

Recently I bumped into a intersing question on stackoverflow.com. The problem was that user had a view but wanted to have some input elements based on variable model. I mean if model passed to view is a, render a Email text input and if it is b then render Name text input. But in mvc you can pass only one model to view. So I suggested have a base model and base view and by checking the type of model in view load the related view using partial as below:

 public ActionResult Base()
        {
            return View(new DerviedOne());
        }

 public class BaseModel
    {
        public int Id { get; set; }
    }

    public class DerviedOne : BaseModel
    {
        public string Email { get; set; }
    }

    public class DerviedTwo : BaseModel
    {
        public string Name { get; set; }
    }
 @using Models
@model Models.BaseModel

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


<h2>Base</h2>


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()


<div class="form-horizontal">

<h4>BaseModel</h4>

        <hr/>
        @Html.ValidationSummary(true, "", new {@class = "text-danger"})

<div class="form-group">

<div class="col-md-offset-2 col-md-10">
                @Html.TextBoxFor(x=>x.Id)
                <input type="submit" value="Create" class="btn btn-default"/>
            </div>

        </div>

    </div>


    if(Model is DerviedOne)
     {
         Html.RenderPartial("DerviedOneView", Model as DerviedOne);
     }

    if (Model is DerviedTwo)
    {
        Html.RenderPartial("DerviedTwoView", Model as DerviedTwo);
    }
}
Advertisements

New Dynamic CRM Customization project

My desk at work with a lovely monitor! (it is verrry wide)

My desk at work with a lovely monitor! (it is verrry wid)

About 10 months ago I was offered to customize MS Dynamic CRM for an educational institute. I had not any experience with any CRM software and even did not know what is all about. The employer offered me this project because I had skills (and still have) in .NET and as you may know, Dynamic CRM is developed in .NET.

I started searching and studying. Those days there were not such resources (now it is better) and there were only two or three books and some blogs and plus Microsoft community (MSDN). Blogs arr better than two others, although people at MSDN are very helpful, but I think it is not enough…

In that project I created a plugin to send SMS to customers, created a application to sync CRM with their web application (developed in php) and …. this project finished about 7 months ago.

After 9 months, I was offered a new CRM customization porject, in a company which sells Server and Network equipment  and hardware. The deadline was so short and there were a lot of new things I had to learn. Main focus on this project was on creating a web service to be called by abas ERP software to send data to CRM, to be short I mean syncing. But aside from web service, there were some requirements that in first glance seemed easy. Actually they were not. I thought I could solve them without developing, but it appeared that for single a workflow I should write custom code!

The businesses owner wanted a funnel chart to show opportunities in three different stages. First problem was make the head developer understand how funnel chart works! (I did not know either at first) and second was implementing their custom stages of opportunities process.

For funnel chart to work, you should have field which shows stages, like “First”, “Second” and … As I read in examples, I had to initialize a filed called Phase Line to make it work with funnel chart. But our stages was not as easy as setting the field with “Save” or “Update” events of opportunity. They want to show opportunities with at least one won quote !!!!

So what did I do ?

I developed a custom  workflow on quote deletion event to check it if causes new stages for opportunity and  also developed a plugin for Win event of opportunity. This events update a custom option set field that is used in funnel char.