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

            /*_context.Entry(planProLabels).State = EntityState.Modified;*/
            _context.Entry(mappedPlanProLabels).State = EntityState.Modified;

            try
            {
                await SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlanProLabelsExists(id))
                {
                    return(false);
                    // planProLabels not found
                }
                else
                {
                    throw;
                }
            }
            return(true);
            // it worked, so return true
        }
コード例 #2
0
 public static Models.PlanProLabels MapPlanProLabels(Domain.Models.PlanProLabels planProLabels)
 {
     return(new Models.PlanProLabels
     {
         PlanId = planProLabels.PlanId,
         PlanProLabelsId = planProLabels.PlanProLabelsId,
         Labels = planProLabels.Labels
     });
 }
        /// <summary>
        /// Wraps a call to EntityFramework Core Add. The call is made with a mapped entity (DataAccess.Models.PlanProLabels) 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.PlanProLabels</returns>
        public void Add(Domain.Models.PlanProLabels entity)
        {
            var mappedEntity = Mapper.MapPlanProLabels(entity);

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