Exemplo n.º 1
0
        /// <summary>
        /// Edits a given training
        /// </summary>
        /// <param name="actualRequest">the client request to be handled</param>
        /// <returns>the response to the given request</returns>
        private async Task <ActualRequest> EditTrainingAsync(ActualRequest actualRequest)
        {
            Request request = actualRequest.Request;
            TrainingSocketsModel training = JsonSerializer.Deserialize <TrainingSocketsModel>(request.Argument.ToString());
            bool editResult = await trainingRepo.EditTrainingAsync(training);

            Request responseRequest = new Request
            {
                ActionType = ActionType.TRAINING_EDIT.ToString(),
                Argument   = JsonSerializer.Serialize(editResult)
            };

            return(new ActualRequest
            {
                Request = responseRequest,
                Images = null
            });
        }
Exemplo n.º 2
0
        public async Task <bool> EditTrainingAsync(TrainingSocketsModel training)
        {
            using (ShapeAppDbContext ctx = new ShapeAppDbContext())
            {
                Training trainingDb = await ctx.Training.FirstAsync(t => t.Id == training.Id);

                if (!string.IsNullOrEmpty(training.Title))
                {
                    trainingDb.Title = training.Title;
                }
                if (!string.IsNullOrEmpty(training.Type))
                {
                    trainingDb.Type = training.Type;
                }
                if (training.Duration > 0)
                {
                    trainingDb.Duration = training.Duration;
                }
                if (training.TimeStamp.Year != 1)
                {
                    trainingDb.TimeStamp = training.TimeStamp;
                }

                trainingDb.IsCompleted = training.Completed;
                trainingDb.IsPublic    = training.Global;

                try
                {
                    ctx.Training.Update(trainingDb);
                    await ctx.SaveChangesAsync();
                }
                catch (Exception e) {
                    return(false);
                }

                return(true);
            }
        }