Ejemplo n.º 1
0
        public IActionResult Save(TeamViewModel vm)
        {
            try
            {
                bool isNew = vm.Id == Guid.Empty;
                vm.UserId = CurrentUserId;

                IEnumerable <Guid> oldMembers = vm.Members.Where(x => x.Id != Guid.Empty).Select(x => x.Id);

                OperationResultVo <Guid> saveResult = teamAppService.Save(CurrentUserId, vm);

                if (saveResult.Success)
                {
                    string url = Url.Action("Index", "Team", new { area = string.Empty, id = vm.Id.ToString(), pointsEarned = saveResult.PointsEarned });

                    Notify(vm, oldMembers);

                    bool recruiting = !vm.RecruitingBefore && vm.Recruiting;
                    GenerateTeamPost(vm, isNew, recruiting);


                    if (isNew)
                    {
                        NotificationSender.SendTeamNotificationAsync($"New team Created: {vm.Name}");
                    }

                    return(Json(new OperationResultRedirectVo(saveResult, url)));
                }
                else
                {
                    return(Json(new OperationResultVo(false)));
                }
            }
            catch (Exception ex)
            {
                return(Json(new OperationResultVo(ex.Message)));
            }
        }