public async Task <IActionResult> DeleteAspNetUser(long id) { var entity = await DB_TABLE.FindAsync(id); if (entity == null) { return(NotFound()); } var result = Check(Operation.Delete); if (result.Fail()) { return(result); } var identityResult = await UserManager.SetLockoutEndDateAsync(entity, DateTimeOffset.MaxValue); if (identityResult.Succeeded) { identityResult = await UserManager.UpdateSecurityStampAsync(entity); } if (identityResult.Succeeded) { Log(DB_TABLE.GetName(), Operation.Delete, null, GetModel(entity)); return(NoContent()); } return(BadRequest(string.Join(";", identityResult.Errors.Select(e => e.Description)))); }
public async Task <ActionResult <CompanyModel> > PostCompany(CompanyCreateModel model) { var result = Check(Operation.Create); if (result.Fail()) { return(result); } var entity = new Company { Name = model.Name }; DB_TABLE.Add(entity); await DB.SaveChangesAsync(); var user = new AspNetUser { UserName = model.Name, Email = model.Email, Company_Id = entity.Id, Level = AspNetUserLevel.Company }; var identityResult = await UserManager.CreateAsync(user, model.Password); if (identityResult.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false); if (User.Identity is ClaimsIdentity) { ((ClaimsIdentity)User.Identity).AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(), ClaimValueTypes.Integer64)); Log(DB_TABLE.GetName(), Operation.Create, null, GetModel(entity)); Log(DB.Users.GetName(), Operation.Create, null, model); } return(CreatedAtAction(nameof(GetCompany), new { id = entity.Id }, GetModel(entity))); } if ((entity = await DB_TABLE.FindAsync(entity.Id)) != null) { DB_TABLE.Remove(entity); await DB.SaveChangesAsync(); } return(BadRequest(string.Join(";", identityResult.Errors.Select(e => e.Description)))); }
public async Task <IActionResult> DeleteJobScript(long id) { var entity = await DB_TABLE.FindAsync(id); var campaign = entity?.Job?.Campaign; var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(DB.Jobs, Operation.Update, campaign.Id); if (result.Fail()) { return(result); } DB_TABLE.Remove(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Delete, campaign.Id, GetModel(entity)); return(NoContent()); }
public async Task <IActionResult> DeleteCompanyIncome(long id) { var entity = await DB_TABLE.FindAsync(id); if (entity == null) { return(NotFound()); } var result = Check(entity.Company_Id == COMPANY_ID, Forbidden).OkNull() ?? Check(Operation.Delete); if (result.Fail()) { return(result); } DB_TABLE.Remove(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Delete, null, GetModel(entity)); return(NoContent()); }
public async Task <IActionResult> DeleteTariffCondition(long id) { var entity = await DB_TABLE.FindAsync(id); if (entity == null) { return(NotFound()); } var result = Check(DB.Tariffs, Operation.Update); if (result.Fail()) { return(result); } DB_TABLE.Remove(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Delete, null, GetModel(entity)); return(NoContent()); }