示例#1
0
        public MealEntryViewModel MapMealEntry(MealEntry mealEntry)
        {
            var mealEntryViewModel = new MealEntryViewModel
            {
                PetId       = mealEntry.PetId,
                MealEntryId = mealEntry.MealEntryId,
                Calories    = mealEntry.Calories,
                MealTime    = mealEntry.MealTime
            };

            return(mealEntryViewModel);
        }
        }// End CreateMealItem[Post].


        public async Task<IActionResult> MealEntryUpdate( string userName, Guid loginToken, Guid mealId )
        {
            if ( ModelState.IsValid )
            {
                ApplicationUser user = await _users.ReadAsync(userName);// Read user from the repository
                user.RemoteLoginToken = Guid.NewGuid();                 // Create a login token, similar to a "session id"
                MealEntry meal = await _meal.ReadAsync(mealId);

                var mealModel = new MealEntryViewModel
                {
                    UserName = meal.UserName,
                    Patient = meal.Patient,
                    TotalCarbs = meal.TotalCarbs,
                    Date = meal.CreatedAt,
                    Timestamp = meal.Timestamp,
                    MealItems = meal.MealItems,
                };


                await _meal.UpdateAsync( meal.Id, mealModel.GetNewMealEntry() );

                return new JsonResult(                                  // This implements IActionResult. If you were 
                        new                                             //      to inspect the output, you would see a 
                        {                                               //      Json-formatted string.
                            success = true,
                            errorCode = ErrorCode.NO_ERROR,
                            remoteMealToken = _meal.ToString(),
                            meal.UserName,
                            meal.Patient,
                            meal.TotalCarbs,
                            meal.CreatedAt,
                            meal.Timestamp,
                            meal.MealItems
                        }
                        );

            }//end if(ModelState.IsValid)

            return new JsonResult(
                    new
                    {
                        success = false,
                        errorCode = ErrorCode.UNKNOWN
                    }
                );

        }//end MealEntrySync
示例#3
0
        } // Create


        public async Task UpdateAsync( Guid id, MealEntryViewModel mealentryVM )
        {
            var oldMealEntry = await ReadAsync( id );
            if( oldMealEntry != null )
            {
    			oldMealEntry.UserName = mealentryVM.UserName;
    			oldMealEntry.User = mealentryVM.User;
    			oldMealEntry.TotalCarbs = mealentryVM.TotalCarbs;
    			oldMealEntry.Date = mealentryVM.Date;
    			oldMealEntry.Timestamp = mealentryVM.Timestamp;
    			oldMealEntry.MealItems = mealentryVM.MealItems;
                _db.Entry( oldMealEntry ).State = EntityState.Modified;
                await _db.SaveChangesAsync();
                return;
            }

        } // UpdateAsync