Beispiel #1
0
        /// <summary>
        /// This method tries to update an entity in the database through setting EntityFramework Core's Entry property to EntityState.Modified. If the update fails an exception is thrown. If the update succeeds then the claim parameter object passed in is saved to the database.
        /// </summary>
        /// <param name="claim"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <bool> ModifyStateAsync(Domain.Models.Claims claim, int id)
        {
            var mappedClaim = Mapper.MapClaims(claim);

            /*_context.Entry(claim).State = EntityState.Modified;*/
            _context.Entry(mappedClaim).State = EntityState.Modified;

            try
            {
                await SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClaimExists(id))
                {
                    return(false);
                    // claim not found
                }
                else
                {
                    throw;
                }
            }
            return(true);
            // it worked, so return true
        }
Beispiel #2
0
 public static Models.Claims MapClaims(Domain.Models.Claims claims)
 {
     return(new Models.Claims
     {
         ClaimId = claims.ClaimId,
         PolicyId = claims.PolicyId,
         Description = claims.Description,
         FilingDate = claims.FilingDate
     });
 }
Beispiel #3
0
        /// <summary>
        /// Wraps a call to EntityFramework Core Add. The call is made with a mapped entity (DataAccess.Models.Claims) instead of the domain model passed as a parameter. The DataAccess.Model is used to communicate with EF Core.
        ///
        /// EF Core Add:
        /// Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found, then null is returned.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Domain.Models.Claims</returns>
        public void Add(Domain.Models.Claims entity)
        {
            var mappedEntity = Mapper.MapClaims(entity);

            _context.Set <Claims>().Add(mappedEntity);
        }