예제 #1
0
        public async Task <IActionResult> PutSystem([FromRoute] int id, [FromBody] guardian.service.Models.System system)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != system.Id)
            {
                return(BadRequest());
            }

            _context.Entry(system).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SystemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutModule([FromRoute] int id, [FromBody] Module @module)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != @module.Id)
            {
                return(BadRequest());
            }

            _context.Entry(@module).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ModuleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
 public async Task SaveOrUpdateProfileAsync(Profile profile)
 {
     await _sqlAzureExecutionStrategy.ExecuteAsync(async() =>
     {
         if (profile.ProfileID != 0)
         {
             profile.User = null;//as user already added and in this scenario trying to attach again, hence exception
             _guardianContext.Entry <Profile>(profile).State = EntityState.Modified;
             await _guardianContext.SaveChangesAsync();
         }
         else
         {
             _guardianContext.Profiles.Add(profile);
             await _guardianContext.SaveChangesAsync();
         }
     }, CancellationToken.None);
 }
예제 #4
0
 public async Task SaveOrUpdateProfileAsync(Profile profile)
 {
     if (profile.ProfileID != 0)
     {
         profile.User             = null;//as user already added and in this scenario trying to attach again, hence exception
         profile.LastModifiedDate = DateTime.UtcNow;
         _guardianContext.Entry <Profile>(profile).State = EntityState.Modified;
         await _guardianContext.SaveChangesAsync();
     }
     else
     {
         profile.CreatedDate      = DateTime.UtcNow;
         profile.LastModifiedDate = DateTime.UtcNow;
         _guardianContext.Profiles.Add(profile);
         await _guardianContext.SaveChangesAsync();
     }
 }
예제 #5
0
        public async Task PurgeStaleSessionsAsync(List <LiveSession> locs)
        {
            foreach (var l in locs)
            {
                _guardianContext.Entry(l).State = EntityState.Deleted;
            }

            await _guardianContext.SaveChangesAsync();
        }
예제 #6
0
 public void DeleteUsingEFTest()
 {
     using (var ctx = new GuardianContext())
     {
         //User u = new User() { Name = "VR" };//Not working
         User u = new User()
         {
             UserID = 2
         };                               // working
         ctx.Entry(u).State = EntityState.Deleted;
         ctx.SaveChanges();
     }
 }
예제 #7
0
        //ssm
        public async Task <bool> SaveMarshal(int groupID, long profileID, bool isValidated)
        {
            GroupMarshal grpMarshal = new GroupMarshal()
            {
                GroupID = groupID, ProfileID = profileID, IsValidated = isValidated
            };

            if (!isValidated)
            {
                grpMarshal.CreatedDate      = DateTime.UtcNow;
                grpMarshal.LastModifiedDate = DateTime.UtcNow;
                _guardianContext.GroupMarshals.Add(grpMarshal);
                _guardianContext.SaveChanges();
            }
            else
            {
                grpMarshal.LastModifiedDate = DateTime.UtcNow;
                _guardianContext.Entry <GroupMarshal>(grpMarshal).State = EntityState.Modified;
                _guardianContext.SaveChanges();
            }
            return(true);
        }