示例#1
0
        public IActionResult New()
        {
            try
            {
                LoggerBundle.Trace("Registered PUT request on InviteController.New");
                if (!IsAuthorized(out IActionResult result, u => u.CanInvite))
                {
                    LoggerBundle.Trace("Request not authorized");
                    return(result);
                }

                // create new entry
                String token  = Guid.NewGuid().ToString("N").Substring(0, 16);
                Invite invite = new Invite
                {
                    CreateDate       = DateTime.Now
                    , ExpirationDate = DateTime.Now.AddDays(14)
                    , Token          = token
                };

                using (DataContext dc = DataContextFactory.GetInstance())
                {
                    dc.SetUsers.Attach(AuthorizedUser);
                    AuthorizedUser.Invites.Add(invite);
                    dc.SaveChanges();
                }

                return(Ok(invite.ToJsonDictionary()));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }