示例#1
0
        public async Task <GetLeagueDTO> CreateOrUpdateLeague(NewLeagueDTO newLeague)
        {
            ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal;
            var             userName  = ClaimsPrincipal.Current.Identity.Name;

            return(await leagueService.CreateOrUpdateLeague(newLeague, userName));
        }
示例#2
0
        public async Task <GetLeagueDTO> CreateOrUpdateLeague(NewLeagueDTO newLeague, string userName)
        {
            try
            {
                User user = await _userManager.FindByNameAsync(userName);

                League league = Mapper.Map <League>(newLeague);
                if (league.Id == 0)
                {
                    league.IsActived     = false;
                    league.CreatedUserId = user.Id;
                    league.CreatedDate   = DateTime.UtcNow;
                    league.UpdatedUserId = user.Id;
                    league.UpdatedDate   = DateTime.UtcNow;

                    _repository.Insert(league);
                }
                else
                {
                    league.UpdatedUserId = user.Id;
                    league.UpdatedDate   = DateTime.UtcNow;

                    _repository.Update(league);
                }


                var tagRepository = _repository.GetRepository <Tag>();

                var tag = tagRepository.Queryable().FirstOrDefault(t => t.Slug == league.Slug);

                if (tag == null)
                {
                    tag = new Tag
                    {
                        Avatar    = league.Logo,
                        FullName  = league.FullName,
                        ShortName = league.ShortName,
                        NickName  = league.NickName,
                        Slug      = league.Slug,
                        TagType   = TagType.League
                    };

                    tagRepository.Insert(tag);
                }
                else
                {
                    tag.Avatar    = league.Logo;
                    tag.FullName  = league.FullName;
                    tag.ShortName = league.ShortName;
                    tag.NickName  = league.NickName;
                    tag.Slug      = league.Slug;
                    tag.TagType   = TagType.League;

                    tagRepository.Update(tag);
                }

                await _unitOfWork.SaveChangesAsync();

                return(Mapper.Map <GetLeagueDTO>(league));
            }
            catch (Exception ex)
            {
                throw new Exception(ResponseCodeString.LeagueCreate_Error, ex.InnerException);
            }
        }