Friday 30 December 2016

how to pass & keyword, special char in my mvc controller method

encodeURIComponent(title)

prevent-caching-in-asp-net-mvc

http://stackoverflow.com/questions/10011780/prevent-caching-in-asp-net-mvc-for-specific-actions-using-an-attribute/10011896#10011896



create  a class file : example file name  NoCacheAttribute


 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
    public sealed class NoCacheAttribute : ActionFilterAttribute
    {
       public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
            filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            filterContext.HttpContext.Response.Cache.SetNoStore();
            base.OnResultExecuting(filterContext);
        }
    }


then apply in your mvc controller


 [NoCache]
public class AbcController : Controller
{
    //  write your on code
}
 

Thursday 29 December 2016

allow special character in MVC

write in your web config  

<system.web>      <httpRuntime targetFramework="4.5"
        executionTimeout="240"
         maxRequestLength="20480"
        minFreeThreads="88"
     minLocalRequestFreeThreads="76"
    relaxedUrlToFileSystemMapping="true"/>

</system.web>

Wednesday 28 December 2016

Getting SqlException "Invalid column name 'User_Id' from EF4 code-only

case 1- you need to check your current domain model and mapping.
   (i) May be you added two times same property/ column name,
   (ii) you may add any FK which name is changed in your child  table, then you need to add fluent API

  example :-

 suppose your domain class

Parent class

public class User : Entity<int>, IAggregateRoot
    {
        public User()
        {
            Events = new Collection<IDomainEvent>();
        }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public virtual ICollection<ErrorLog> ErrorLogs { get; set; }     
    }

Child class

public class ErrorLog : Entity<int>, IAggregateRoot
    {
        public DateTime ErrorDate { get; set; }
    
        public string ErrorDescription { get; set; }     
        public int? ByUserId{ get; set; }   
        public virtual User User { get; set; }
    }

       Property(t => t.UserId).HasColumnName("UserId");

  HasOptional(t => t.User)
                .WithMany(t => t.ErrorLogs)
                .HasForeignKey(d => d.ByUserId);
----------------------------------------------------------------------------------

case 2 :- You may not have any FK relation with your current domain model, but you mention the collection object in your parent  class, then you need to remove that.






 

Tuesday 27 December 2016

Method may only be called on a Type for which Type.IsGenericParameter is true.

1- you need to register your event in domain registry
2- you need to add your event in your domain model constructor

Friday 23 December 2016

sql alter

--   DROP CONSTRAINT --
IF EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N'[dbo].[FK_EmailServicesSendActivityLUT_EmailServicesContactLUT]')
 AND parent_object_id = OBJECT_ID(N'[dbo].[EmailServicesCampaignContact]'))
   BEGIN
    ALTER TABLE [dbo].[EmailServicesCampaignContact]
     DROP CONSTRAINT [FK_EmailServicesSendActivityLUT_EmailServicesContactLUT]
   END



--   DROP COLUMN --
IF EXISTS (
  SELECT *
  FROM   sys.columns   WHERE  object_id = OBJECT_ID(N'EmailServicesContactLUT') AND name = 'EmailServicesContactLUTId'
)
Begin
ALTER TABLE dbo.EmailServicesCampaignContact DROP COLUMN EmailServicesContactLUTId
End


--   DROP TABLE --
IF (EXISTS (SELECT *
                 FROM INFORMATION_SCHEMA.TABLES
                 WHERE TABLE_SCHEMA = 'dbo'
                 AND  TABLE_NAME = 'EmailServicesContactLUT'))
Begin
 DROP TABLE EmailServicesContactLUT
End



--  Add column
IF NOT EXISTS (
  SELECT *
  FROM   sys.columns   WHERE  object_id = OBJECT_ID(N'EmailServicesCampaignContact') AND name = 'ConstituentLUTId'
)
Begin
ALTER TABLE EmailServicesCampaignContact  Add  ConstituentLUTId int NOT NULL
End


--  ADD  CONSTRAINT
IF EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N'[dbo].[FK_EmailServicesCampaignContact_ConstituentLUT]')
 AND parent_object_id = OBJECT_ID(N'[dbo].[EmailServicesCampaignContact]'))
   BEGIN
ALTER TABLE [dbo].[EmailServicesCampaignContact]  WITH CHECK ADD  CONSTRAINT [FK_EmailServicesCampaignContact_ConstituentLUT]
FOREIGN KEY([ConstituentLUTId])
REFERENCES [dbo].[ConstituentLUT] ([ConstituentLUTId])
ALTER TABLE [dbo].[EmailServicesCampaignContact] CHECK CONSTRAINT [FK_EmailServicesCampaignContact_ConstituentLUT]
End



-- DROP COLUMN
IF EXISTS (
  SELECT *
  FROM   sys.columns   WHERE  object_id = OBJECT_ID(N'EmailServicesCampaignContact') AND name = 'EmailAddress'
)
Begin
ALTER TABLE dbo.EmailServicesCampaignContact DROP COLUMN EmailAddress
End



-- DROP COLUMN
IF EXISTS (
  SELECT *
  FROM   sys.columns   WHERE  object_id = OBJECT_ID(N'EmailServicesCampaignContact') AND name = 'ConstituentLUT'
)
Begin
ALTER TABLE dbo.EmailServicesCampaignContact DROP COLUMN ConstituentLUT
End

drop CONSTRAINT and add CONSTRAINT

/*  DROP CONSTRAINT   */
ALTER TABLE [dbo].[EmailServicesCampaignContact] DROP CONSTRAINT [FK_EmailServicesSendActivityLUT_EmailServicesContactLUT]




/*  ADD  CONSTRAINT  */
ALTER TABLE [dbo].[EmailServicesCampaignContact]  WITH CHECK ADD  CONSTRAINT [FK_EmailServicesCampaignContact_ConstituentLUT]
FOREIGN KEY([ConstituentLUTId])
REFERENCES [dbo].[ConstituentLUT] ([ConstituentLUTId])
ALTER TABLE [dbo].[EmailServicesCampaignContact] CHECK CONSTRAINT [FK_EmailServicesCampaignContact_ConstituentLUT]

drop column if exist

IF EXISTS (
  SELECT *
  FROM   sys.columns   WHERE  object_id = OBJECT_ID(N'emailTable') AND name = 'EmailAddress'
)
Begin
ALTER TABLE dbo.emailTable DROP COLUMN EmailAddress
End

drop table if exist


IF (EXISTS (SELECT *
                 FROM INFORMATION_SCHEMA.TABLES
                 WHERE TABLE_SCHEMA = 'dbo'
                 AND  TABLE_NAME = empTable))
Begin
 DROP TABLE empTable
End

Wednesday 21 December 2016

Tuesday 20 December 2016

open computer management shortcut

compmgmt.msc

how to run window service

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe put you path

ex:


C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe E:\Test2\Test2_app\app.WindowsService.Jobtest\bin\Debug\crm.Service.JobOnline.exe