public async Task<ActionResult<ScriptElementModel>> PostScriptElement(ScriptElementCreateModel model) { var campaign = DB.Scripts.Find(model.Script_Id)?.Campaign; var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(DB.Scripts, Operation.Update); if (result.Fail()) return result; var entity = GetEntity(model); DB_TABLE.Add(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Create, campaign.Id, GetModel(entity)); return CreatedAtAction(nameof(GetScriptElement), new { id = entity.Id }, GetModel(entity)); }
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 <ActionResult <CompanyIncomeModel> > PostCompanyIncome(CompanyIncomeCreateModel model) { var result = Check(model.Company_Id == COMPANY_ID, Forbidden).OkNull() ?? Check(Operation.Create); if (result.Fail()) { return(result); } var entity = GetEntity(model); DB_TABLE.Add(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Create, null, GetModel(entity)); return(CreatedAtAction(nameof(GetCompanyIncome), new { id = entity.Id }, GetModel(entity))); }
public async Task <ActionResult <TariffConditionModel> > PostTariffCondition(TariffConditionCreateModel model) { var result = Check(DB.Tariffs, Operation.Update); if (result.Fail()) { return(result); } var entity = GetEntity(model); DB_TABLE.Add(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Create, null, GetModel(entity)); return(CreatedAtAction(nameof(GetTariffCondition), new { id = entity.Id }, GetModel(entity))); }
public async Task <ActionResult <AspNetUserRoleModel> > PostAspNetUserRole(AspNetUserRoleCreateModel model) { var result = Check(Operation.Create); if (result.Fail()) { return(result); } var entity = GetEntity(model); DB_TABLE.Add(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Create, null, GetModel(entity)); return(CreatedAtAction(nameof(GetAspNetUserRole), new { id = entity.Id }, GetModel(entity))); }
public async Task <ActionResult <LeadPropertyModel> > PostLeadProperty(LeadPropertyCreateModel model) { var campaign = DB.Campaigns.Find(model.Campaign_Id); var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(DB.Campaigns, Operation.Update); if (result.Fail()) { return(result); } var entity = GetEntity(model); DB_TABLE.Add(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Create, campaign.Id, GetModel(entity)); return(CreatedAtAction(nameof(GetLeadProperty), new { id = entity.Id }, GetModel(entity))); }
public async Task <ActionResult <AspNetRoleModel> > PostAspNetRole(AspNetRoleCreateModel model) { var result = Check(Operation.Create); if (result.Fail()) { return(result); } var entity = new AspNetRole { Name = model.Name, NormalizedName = model.Name.ToUpper(), ConcurrencyStamp = Guid.NewGuid().ToString(), PermissibleLevel = model.PermissibleLevel }; DB_TABLE.Add(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Create, null, GetModel(entity)); return(CreatedAtAction(nameof(GetAspNetRole), new { id = entity.Id }, GetModel(entity))); }