Tuesday, 2 April 2019

How to store DateTimeOffset and Display local Datetime - Working is DateTimeOffset in .Net, MVC

Recently i have been working on a website which might get used globally and requires datetime to be displayed according to User.

There are two things happening in the application:

1. There is Feed coming from different sources which contains DateTime. I am saving that DateTime in SqlServer as DateTimeOffset. Sql server stores it like : 2019-04-02 11:24:00.0000000 +00:00.

2. Now i have MVC application where i would like to display date time in local format, i live in London so in addition to normal DateTime conversion, i also face the challenge of Daylight saving times. All that can be handled using JavaScript. Following is what i am doing. I am creating a Javascript object "new Date" then converting that to Locale string, here JS will use user's Locale and show the DateTime.

 var latestate = new Date('@Model.LatestItemDateTime.ToLocalTime().ToString("dd/MM/yyyy hh:mm:ss")').toLocaleString();


It seems to work and i feel it's simpler solution. This might not fit in every development project it gives an overview of how Javascript can handle locale.        

Monday, 11 January 2016

What is Domain Driven Design (DDD)?

This is a very small post and i am not going to write about Domain Driven Design (DDD) in deep detail. So what is Domain Driven Design?

As per name says Domain driven design can be a driver for software architecture and implementation of domain model. My recent experience is in Insurance, we are working on Underwriting system. I say we use DDD design pattern for development and we do it by:

  1. Understanding business domain as much as possible by asking relevant questions about Business Domain. I know, learning about any business in full is not easy or possible, but you have to start small, refine, grow, refine!
  2. Create abstraction of that domain in the form of Diagram and implement that abstraction as part of system.
  3. We use Test driven development (TDD) as a driver for domain implementation, that can be Abstraction implementation or full implementation. TDD does not have to be part of DDD but that's what i have experienced that it helps in keeping Domain driven design boundaries in tact.
  4. Once Domain boundaries are implemented as abstraction, one can go and refine it as knowledge of business domain increases. This is like any other profession where the more you work in an industry the more knowledge you have and the better and efficient you are.

So above is very simplistic view of DDD, i could go into details but that was not the point.

Tuesday, 17 June 2014

How to prevent subversion commits without comments

I try to keep my posts short and this one is short as well.

You can have following script in a batch file and can be run on SVN Server


@echo off
rem http://stackoverflow.com/questions/1928023/how-can-i-prevent-subversion-commits-without-comments
::
:: Stops commits that have empty log messages.
::

@echo off

setlocal

rem Subversion sends through the path to the repository and transaction id
set REPOS=%1
set TXN=%2

rem check for an empty log message
svnlook log %REPOS% -t %TXN% | findstr . > nul
if %errorlevel% gtr 0 (goto err) else exit 0

:err
echo. 1>&2
echo Your commit has been blocked because you didn't give any log message 1>&2
echo. 1>&2
echo If your commit is related to a story/bug, please use the following format: 1>&2
echo #^ ^ ^ 1>&2
echo     #^ ^ ^ 1>&2
echo. 1>&2
echo Otherwise please write a log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1

Tuesday, 10 June 2014

Pareto’s principle in marketing



I’m sure you’re familiar with these examples of applying Pareto’s principle in marketing:
·         80% of profits come from 20% of customers
·         80% of product sales from 20% of products
·         80% of sales from 20% of advertising
·         80% of customer complaints from 20% of customers
·         80% of sales from 20% of the sales team

Wednesday, 11 September 2013

Basics of Agile Scrum

I went to a course yesterday that made me think about few things.


               1. Projects where people think they are using Scrum but they are not
               2. Teams where they are doing certain things which makes it waterfall, not Scrum
               3. People think Scrum is for every team


What is Scrum?
        Basically Scrum is a framework for Complex problems or product development and delivering product/projects at highest possible standard and value.

  1. It is lightweight
  2. Simple to understand
  3. Extremely difficult to master


What is Scrum Framework?
         Scrum Framework consist of
  1. Scrum Team
  2. Scrum Roles - Product Owner, Scrum Master, Scrum Team
  3. Events - Planning, Estimation, Review etc

Above is very basic idea of Scrum, in next post i will talk about Scrum Foundations (Transparency, Inspection, Adaptation)                      

Tuesday, 28 August 2012

WPF ScrollViewer Drag and Scroll Behavior

Here i am trying to add behavior to my ScrollViewer in WPF, where when i am dragging anything to ItemsControl and list is longer than User should be able  to drag that item to end of the list and list should scroll automaticall.

Following code will include drag/scroll behavior in ScrollViewer!

public class DragBehavior : Behavior
    {
        const double Tolerance = 100;
        const double Offset = 10;

        protected override void OnAttached()
        {
            var svFavourites = AssociatedObject;
            AssociatedObject.DragOver += (sender, e) =>
                {
                    var verticalPos = e.GetPosition(svFavourites).Y;

                    if (verticalPos < Tolerance)
                    {
                        svFavourites.ScrollToVerticalOffset(svFavourites.VerticalOffset - Offset);
                    }
                    else if (verticalPos > svFavourites.ActualHeight - Tolerance)
                    {
                        svFavourites.ScrollToVerticalOffset(svFavourites.VerticalOffset + Offset);
                    }
                };
        }
    }


To use the above Behavior just add following inside ScrollViewer in XAML


                   
               



Wednesday, 18 July 2012

Previous method "method name" requires a return value or an exception to throw

Today i came across this error, i took me a while to figure out the solution. following is an example


[TestFixture]
    public class RhinoTest
    {
        public interface ICompany
        {
            IPerson Contact { get; }
        }

        public interface IPerson
        {
            string Name { get; }
            string Address { get; }
        }

        [Test]
        public void RhinoMockCanStubMultipleLevels()
        {
            var company = MockRepository.GenerateMock();
            company.Stub(x => x.Contact.Name).Return("contact name");
            company.Stub(x => x.Contact.Address).Return("address");
            Assert.That(company.Contact.Name, Is.EqualTo("contact name"));
        }       
    }

 Above gave me error "Previous method "method name" requires a return value or an exception to throw" on Red line. Following was my solution, i had to Mock Contact separately.

[TestFixture]
    public class RhinoTest
    {
        public interface ICompany
        {
            IPerson Contact { get; }
        }

        public interface IPerson
        {
            string Name { get; }
            string Address { get; }
        }

        [Test]
        public void RhinoMockCanStubMultipleLevels()
        {
            var company = MockRepository.GenerateMock();
            var contact = MockRepository.GenerateMock();
            contact.Stub(x => x.Name).Return("contact name");
            contact.Stub(x => x.Address).Return("address");
            Assert.That(company.Contact.Name, Is.EqualTo("contact name"));
        }       
    }