/// <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 planReviews parameter object passed in is saved to the database.
        /// </summary>
        /// <param name="planReviews"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <bool> ModifyStateAsync(Domain.Models.PlanReviews planReviews, int id)
        {
            var mappedPlanReviews = Mapper.MapPlanReviews(planReviews);

            /*_context.Entry(planReviews).State = EntityState.Modified;*/
            _context.Entry(mappedPlanReviews).State = EntityState.Modified;

            try
            {
                await SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlanReviewsExists(id))
                {
                    return(false);
                    // planReviews not found
                }
                else
                {
                    throw;
                }
            }
            return(true);
            // it worked, so return true
        }
Esempio n. 2
0
 public static Models.PlanReviews MapPlanReviews(Domain.Models.PlanReviews planReviews)
 {
     return(new Models.PlanReviews
     {
         PlanReviewId = planReviews.PlanReviewId,
         CustomerId = planReviews.CustomerId,
         Review = planReviews.Review
     });
 }
        /// <summary>
        /// Wraps a call to EntityFramework Core Add. The call is made with a mapped entity (DataAccess.Models.PlanReviews) 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.PlanReviews</returns>
        public void Add(Domain.Models.PlanReviews entity)
        {
            var mappedEntity = Mapper.MapPlanReviews(entity);

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