Thursday 14 January 2016

add new column with guid not null in sql



--add new column with guid not null


ALTER TABLE [dbo].CustomContent ADD CustomContentGuid uniqueidentifier NOT NULL Default NewID()

how to rename column in sql

-- Rename column Name

sp_RENAME '[CustomContent].[CustomContentName]' , 'CustomContentData', 'COLUMN'



 
 

 

get enum id from value in C#

//(int)Enum.Parse(typeof(StaticSectionType), apiCustomContent.StaticSectionName),

Tuesday 12 January 2016

how to create webapi in C#

/// <summary>

/// Get StaticSection

/// </summary>

/// <returns></returns>

[System.Web.Http.HttpGet]

[ValidateApiAccessToken]

[ApiExceptionFilter(LoggerType = typeof(VolunteerApiLogger))]

[ResponseType(typeof(List<ApiStaticSection>))]

[System.Web.Http.Route("~/api/Volunteering/StaticSection/")]

public HttpResponseMessage GetStaticSection()


{
try


{
var orgConnection = OrganizationGuid.HasValue ? DataSources.ConnectionDictionary[OrganizationGuid.Value] : String.Empty;


 
var apiStaticSection = new List<ApiStaticSection>();

var entityModel = _customContentService.GetStaticSection(orgConnection);

if (entityModel == null)

return Request.CreateResponse(HttpStatusCode.OK, apiStaticSection);

apiStaticSection.AddRange(entityModel.Select(item => new ApiStaticSection


{

StaticSectionId = item.StaticSectionId,

SectionName = item.SectionName,

SectionType = item.SectionType

}));
return Request.CreateResponse(HttpStatusCode.OK, apiStaticSection);


}
catch (PersistenceValidationException ex)


{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.BrokenRules);


}

}

how to create unique key with two column in sqlserver

ALTER TABLE CustomContent
ADD CONSTRAINT uq_StaticSectionID_OrgID UNIQUE (StaticSectionId, OrganizationId);