예제 #1
0
        public async Task <IActionResult> DeleteJob(long id)
        {
            var entity = await DB_TABLE.Include(e => e.JobContacts).Include(e => e.JobScripts).Include(e => e.InboxScripts).FirstOrDefaultAsync(e => e.Id == id);

            var campaign = entity?.Campaign;

            var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(Operation.Delete, campaign.Id);

            if (result.Fail())
            {
                return(result);
            }

            {
                DB.RemoveRange(entity.JobContacts);
                DB.RemoveRange(entity.JobScripts);
                DB.RemoveRange(entity.InboxScripts);
                DB_TABLE.Remove(entity);
            }

            await DB.SaveChangesAsync();

            var operation_Id = Guid.NewGuid();

            {
                Log(DB_TABLE.GetName(), Operation.Delete, operation_Id, campaign.Id, GetModel(entity));
                Get <JobContactsController>().Log(Operation.Delete, operation_Id, campaign.Id, entity.JobContacts);
                Get <JobScriptsController>().Log(Operation.Delete, operation_Id, campaign.Id, entity.JobScripts);
                Get <InboxScriptsController>().Log(Operation.Delete, operation_Id, campaign.Id, entity.InboxScripts);
            }

            return(NoContent());
        }
        public async Task <IActionResult> DeleteAspNetRole(long id)
        {
            var entity = await DB_TABLE.Include(e => e.RolePermissions).Include(e => e.UserRoles).FirstOrDefaultAsync(e => e.Id == id);

            if (entity == null)
            {
                return(NotFound());
            }

            var result = Check(Operation.Delete);

            if (result.Fail())
            {
                return(result);
            }

            {
                DB.RemoveRange(entity.RolePermissions);
                DB.RemoveRange(entity.UserRoles);
                DB_TABLE.Remove(entity);
            }

            await DB.SaveChangesAsync();

            var operation_Id = Guid.NewGuid();

            {
                Log(DB_TABLE.GetName(), Operation.Delete, operation_Id, null, GetModel(entity));
                Get <AspNetRolePermissionsController>().Log(Operation.Delete, operation_Id, null, entity.RolePermissions);
                Get <AspNetUserRolesController>().Log(Operation.Delete, operation_Id, null, entity.UserRoles);
            }

            return(NoContent());
        }
        public async Task <IActionResult> DeleteCampaign(long id)
        {
            var entity = await DB_TABLE
                         .Include(e => e.ContactGroups) // stop
                         .Include(e => e.Jobs)          // stop
                         .Include(e => e.Leads)         // stop
                         .Include(e => e.Scripts)       // stop
                         .Include(e => e.Gateways)
                         .ThenInclude(e => e.GatewayStreams)
                         .Include(e => e.ContactProperties)
                         .Include(e => e.LeadProperties)
                         .Include(e => e.UserRoles)
                         .FirstOrDefaultAsync(e => e.Id == id);

            if (entity == null)
            {
                return(NotFound());
            }

            var campaign_Id = id;

            var result =
                Check(entity.Company_Id == COMPANY_ID, Forbidden).OkNull() ??
                Check(Operation.Delete, campaign_Id).OkNull() ??
                Check(entity.ContactGroups.Count == 0, Forbidden, string.Format(Strings.Cascade_Message, Strings.Campaign_Entity, Strings.ContactGroup_List)).OkNull() ??
                Check(entity.Jobs.Count == 0, Forbidden, string.Format(Strings.Cascade_Message, Strings.Campaign_Entity, Strings.Job_List)).OkNull() ??
                Check(entity.Leads.Count == 0, Forbidden, string.Format(Strings.Cascade_Message, Strings.Campaign_Entity, Strings.Lead_List)).OkNull() ??
                Check(entity.Scripts.Count == 0, Forbidden, string.Format(Strings.Cascade_Message, Strings.Campaign_Entity, Strings.Script_List));

            if (result.Fail())
            {
                return(result);
            }

            {
                DB.RemoveRange(entity.Gateways.SelectMany(e => e.GatewayStreams));
                DB.RemoveRange(entity.Gateways);
                DB.RemoveRange(entity.ContactProperties);
                DB.RemoveRange(entity.LeadProperties);
                DB.RemoveRange(entity.UserRoles);
                DB_TABLE.Remove(entity);
            }

            await DB.SaveChangesAsync();

            var operation_Id = Guid.NewGuid();

            {
                Log(DB_TABLE.GetName(), Operation.Delete, operation_Id, campaign_Id, GetModel(entity));
                Get <GatewayStreamsController>().Log(Operation.Delete, operation_Id, campaign_Id, entity.Gateways.SelectMany(e => e.GatewayStreams));
                Get <GatewaysController>().Log(Operation.Delete, operation_Id, campaign_Id, entity.Gateways);
                Get <ContactPropertiesController>().Log(Operation.Delete, operation_Id, campaign_Id, entity.ContactProperties);
                Get <LeadPropertiesController>().Log(Operation.Delete, operation_Id, campaign_Id, entity.LeadProperties);
                Get <AspNetUserRolesController>().Log(Operation.Delete, operation_Id, campaign_Id, entity.UserRoles);
            }

            Log(DB_TABLE.GetName(), Operation.Delete, campaign_Id, GetModel(entity));

            return(NoContent());
        }
        public async Task<IActionResult> DeleteScriptElement(long id)
        {
            var entity = await DB_TABLE.Include(e => e.ScriptConditions).Include(e => e.ScriptInputParameters).Include(e => e.ScriptOutputParameters).FirstOrDefaultAsync(e => e.Id == id);
            var campaign = entity?.Script?.Campaign;

            var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(DB.Scripts, Operation.Update, campaign.Id);
            if (result.Fail()) return result;

            {
                DB.RemoveRange(entity.ScriptConditions);
                DB.RemoveRange(entity.ScriptInputParameters);
                DB.RemoveRange(entity.ScriptOutputParameters);
                DB_TABLE.Remove(entity);
            }

            await DB.SaveChangesAsync();

            var operation_Id = Guid.NewGuid();
            {
                Log(DB_TABLE.GetName(), Operation.Delete, operation_Id, campaign.Id, GetModel(entity));
                Get<ScriptConditionsController>().Log(Operation.Delete, operation_Id, campaign.Id, entity.ScriptConditions);
                Get<ScriptInputParametersController>().Log(Operation.Delete, operation_Id, campaign.Id, entity.ScriptInputParameters);
                Get<ScriptOutputParametersController>().Log(Operation.Delete, operation_Id, campaign.Id, entity.ScriptOutputParameters);
            }

            return NoContent();
        }
예제 #5
0
        public async Task <IActionResult> DeleteCompany(long id)
        {
            var entity = await DB_TABLE
                         .Include(e => e.Campaigns) // stop
                         .Include(e => e.CompanyExpenses)
                         .Include(e => e.CompanyIncomes)
                         .Include(e => e.Users)
                         .ThenInclude(e => e.UserLogs)
                         .Include(e => e.Users)
                         .ThenInclude(e => e.UserRoles)
                         .FirstOrDefaultAsync(e => e.Id == id);

            if (entity == null)
            {
                return(NotFound());
            }

            var result = Check(Operation.Delete).OkNull() ??
                         Check(entity.Campaigns.Count == 0, Forbidden, string.Format(Strings.Cascade_Message, Strings.Company_Entity, Strings.Campaign_List));

            if (result.Fail())
            {
                return(result);
            }

            {
                DB.RemoveRange(entity.Users.SelectMany(e => e.UserLogs));
                DB.RemoveRange(entity.Users.SelectMany(e => e.UserRoles));
                DB.RemoveRange(entity.Users);
                DB.RemoveRange(entity.CompanyExpenses);
                DB.RemoveRange(entity.CompanyIncomes);
                DB_TABLE.Remove(entity);
            }

            await DB.SaveChangesAsync();

            var operation_Id = Guid.NewGuid();

            {
                Log(DB_TABLE.GetName(), Operation.Delete, null, GetModel(entity));
                Get <AspNetUserLogsController>().Log(Operation.Delete, operation_Id, null, entity.Users.SelectMany(e => e.UserLogs));
                Get <AspNetUserRolesController>().Log(Operation.Delete, operation_Id, null, entity.Users.SelectMany(e => e.UserRoles));
                Get <AspNetUsersController>().Log(Operation.Delete, operation_Id, null, entity.Users);
                Get <CompanyExpensesController>().Log(Operation.Delete, operation_Id, null, entity.CompanyExpenses);
                Get <CompanyIncomesController>().Log(Operation.Delete, operation_Id, null, entity.CompanyIncomes);
            }

            return(NoContent());
        }
예제 #6
0
        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))));
        }
예제 #7
0
        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());
        }
예제 #8
0
        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());
        }