Exemplo n.º 1
0
        public async Task <MainCompetetionResponse> UpdateAsync(MainCompetetion mainCompetetion)
        {
            try
            {
                var mainCompetetionExist = await _genericMainCompetetionRepository.FindByIdAsync(mainCompetetion.MainCompetetionID, new string[] { "SubCompetetions" });

                if (mainCompetetionExist == null)
                {
                    return(new MainCompetetionResponse("mainCompetetion not found"));
                }
                foreach (var subCompetetion in mainCompetetionExist.SubCompetetions)
                {
                    var subCompetetionExist = mainCompetetion.SubCompetetions.Where(m => m.SubCompetetionID == subCompetetion.SubCompetetionID).FirstOrDefault();
                    if (subCompetetionExist == null)
                    {
                        await _subcompetetionRepository.DeleteAsync(subCompetetion.SubCompetetionID);
                    }
                    else
                    {
                        _subcompetetionRepository.UpdateAsync(subCompetetionExist);
                    }
                }
                _genericMainCompetetionRepository.UpdateAsync(mainCompetetion);
                await _unitOfWork.CompleteAsync();

                return(new MainCompetetionResponse());
            }
            catch (Exception ex)
            {
                return(new MainCompetetionResponse(ex.Message));
            }
        }
Exemplo n.º 2
0
        public async Task <MainCompetetionResponse> AddAsync(MainCompetetion mainCompetetion)
        {
            try
            {
                await _genericMainCompetetionRepository.AddAsync(mainCompetetion);

                await _unitOfWork.CompleteAsync();

                return(new MainCompetetionResponse());
            }
            catch (Exception ex)
            {
                return(new MainCompetetionResponse(ex.Message));
            }
        }
 public MainCompetetionResponse(MainCompetetion competetion) : this(true, string.Empty, competetion)
 {
 }
 private MainCompetetionResponse(bool success, string message, MainCompetetion competetion) : base(success, message)
 {
     this.competetion = competetion;
 }