Skip to content

Instantly share code, notes, and snippets.

View alimozdemir's full-sized avatar

Alim ÖZDEMİR alimozdemir

View GitHub Profile
[HttpPatch]
public async Task Patch([FromODataUri] int key, Delta<vw_Song> delta)
{
var changedProps = delta.GetChangedPropertyNames();
var instance = delta.GetInstance();
var updateDict = new Dictionary<string, object>();
if (changedProps.Contains("Status"))
{
updateDict.Add("Status", instance.Status);
if (changedProps.Contains("Status"))
{
await _db.Country_Songs.Where(i => i.SongId == instance.Id)
.UpdateAsync(i => new Country_Songs() { Status = instance.Status });
}
if (changedProps.Contains("Field1"))
{
await _db.Country_Songs.Where(i => i.SongId == instance.Id)
.UpdateAsync(i => new Country_Songs() { Field1 = instance.Field1 });
[HttpPatch]
public async Task<IActionResult> Patch([FromODataUri] int key, Delta<vw_Song> model)
{
var instance = model.GetInstance();
var changedProps = model.GetChangedPropertyNames();
if (changedProps.Contains("Status"))
{
await _db.Country_Songs.Where(i => i.SongId == instance.Id)
.UpdateAsync(i => new Country_Songs() { Status = instance.Status });
}
UPDATE A
SET A.[Status] = @zzz_BatchUpdate_0
FROM [Country_Songs] AS A
INNER JOIN ( SELECT [c].[SongId], [c].[CountryId], [c].[Status]
FROM [Country_Songs] AS [c]
WHERE [c].[SongId] = @zzz_BatchUpdate_1
) AS B ON A.[SongId] = B.[SongId]
AND A.[CountryId] = B.[CountryId]
CREATE VIEW vw_Songs
AS
SELECT s.Id, s.Title, MIN(ISNULL(cs.[Status], 0) + 0) CountryStatus
FROM Song AS s
LEFT JOIN dbo.Country_Songs AS cs ON cs.SongId = s.Id
GROUP BY s.Id, s.Title
[HttpPost]
public async Task<IActionResult> Post(Entity model)
{
_db.Entities.Add(model);
await _db.SaveChangesAsync();
return Created(model);
}
[HttpPatch]
public async Task<IActionResult> Patch([FromODataUri] int key, Delta<Entity> model)
@alimozdemir
alimozdemir / Pagination.cs
Last active June 5, 2020 20:53
Pagination Example
[HttpGet]
public IEnumerable<Entity> Get(int skip = 0, int take = 10)
{
return _db.Entities.Skip(skip).Take(take).ToList();
}
public void ConfigureServices(IServiceCollection services)
{
...
services.Scan(i =>
i.FromCallingAssembly()
.AddClasses(c => c.Where(i => i.IsClass && i.Name.EndsWith("BusinessService")))
.AsImplementedInterfaces()
.WithTransientLifetime()
);
[ApiController]
[Route("[controller]")]
public class ServiceController : ControllerBase
{
private readonly ITransientService _transientService;
private readonly IScopedService _scopedService;
private readonly ISingletonService _singletonService;
public ServiceController(ITransientService transientService, IScopedService scopedService, ISingletonService singletonService)
{
public void ConfigureServices(IServiceCollection services)
{
...
services.Scan(i =>
i.FromCallingAssembly()
.InjectableAttributes()
);
/* Or */
services.Scan(i =>