Example #1
0
        public async Task <IActionResult> PutCompany(long id, CompanyModel model)
        {
            var result = Check(id == model.Id, BadRequest).OkNull() ?? Check(Operation.Update).OkNull() ?? CheckIfMatch(model.Id);

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

            var entity = GetEntity(model);

            DB.Entry(entity).State = EntityState.Modified;
            try { await DB.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DB_TABLE.Any(e => e.Id == id))
                                                                                        {
                                                                                            return(NotFound());
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            throw;
                                                                                        } }

            Log(DB_TABLE.GetName(), Operation.Update, null, model);

            return(NoContent());
        }
        public async Task <IActionResult> PutAspNetRole(long id, AspNetRoleModel model)
        {
            var result = Check(id == model.Id, BadRequest).OkNull() ?? Check(Operation.Update).OkNull() ?? CheckIfMatch(model.Id);

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

            var entity = await DB_TABLE.FirstOrDefaultAsync(e => e.Id == model.Id);

            entity.Name             = model.Name;
            entity.NormalizedName   = model.Name.ToUpper();
            entity.ConcurrencyStamp = Guid.NewGuid().ToString();
            entity.PermissibleLevel = model.PermissibleLevel;

            DB.Entry(entity).State = EntityState.Modified;
            try { await DB.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DB_TABLE.Any(e => e.Id == id))
                                                                                        {
                                                                                            return(NotFound());
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            throw;
                                                                                        } }

            Log(DB_TABLE.GetName(), Operation.Update, null, model);

            return(NoContent());
        }
Example #3
0
        public async Task <IActionResult> PutJobScript(long id, JobScriptModel model)
        {
            if (id != model.Id)
            {
                return(BadRequest());
            }

            var campaign = DB.Jobs.Find(model.Job_Id)?.Campaign;

            var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(DB.Jobs, Operation.Update, campaign.Id).OkNull() ?? CheckIfMatch(model.Id);

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

            var entity = GetEntity(model);

            DB.Entry(entity).State = EntityState.Modified;
            try { await DB.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DB_TABLE.Any(e => e.Id == id))
                                                                                        {
                                                                                            return(NotFound());
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            throw;
                                                                                        } }

            Log(DB_TABLE.GetName(), Operation.Update, campaign.Id, model);

            return(NoContent());
        }
        public async Task <IActionResult> PutCampaign(long id, CampaignModel model)
        {
            if (id != model.Id)
            {
                return(BadRequest());
            }

            var campaign_Id = model.Id;

            var result = Check(model.Company_Id == COMPANY_ID, Forbidden).OkNull() ?? Check(Operation.Update, campaign_Id).OkNull() ?? CheckIfMatch(model.Id);

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

            var entity = GetEntity(model);

            DB.Entry(entity).State = EntityState.Modified;
            try { await DB.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DB_TABLE.Any(e => e.Id == id))
                                                                                        {
                                                                                            return(NotFound());
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            throw;
                                                                                        } }

            Log(DB_TABLE.GetName(), Operation.Update, campaign_Id, model);

            return(NoContent());
        }