public HttpResponseMessage ChangeUserName([FromBody] QuizzerModel model)
        {
            try
            {
                if (HasUpdatePermission(model) == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
                var userEntity = Uow.Users.GetById(model.Id);
                var user       = UserManager.FindById(userEntity.LocalAuthUserId);
                user.UserName = model.UserName;

                UserManager.Update(user);

                userEntity.UserName = user.UserName;
                Uow.Users.Update(userEntity);
                Uow.SaveChanges();
                SvcContainer.UserSvc.ResetStoredUser();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                SvcContainer.LoggingSvc.Log(ex);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
        public void UpdateModel(QuizzerModel model)
        {
            SetAge(model);

            model.IsSelf      = model.Id == _currentUser.Id;
            model.IsParent    = false;
            model.IsDependent = false;

            if (_currentUser.UserType == Entities.Enums.UserTypeEnum.Standard)
            {
                if (model.UserType == Entities.Enums.UserTypeEnum.Child)
                {
                    model.IsDependent = _svcContainer.UserSvc.IsDependent(model.Id);
                }
            }
            else
            {
                if (model.UserType == Entities.Enums.UserTypeEnum.Standard)
                {
                    model.IsParent = _svcContainer.UserSvc.IsParent(model.Id);
                }
            }

            if (model.IsSelf || model.IsParent || model.IsDependent)
            {
                model.IsQuizzmate = true;
            }

            model.Profile.BirthDate = model.Profile.BirthDate.ToLocalTime();
            if (model.IsQuizzmate == false)
            {
                model.UserFullName      = "";
                model.Profile.FirstName = "";
                model.Profile.LastName  = "";
                model.Profile.BirthDate = DateTime.Now;
            }

            if (model.IsFriendRequestPending)
            {
                model.FriendRequestId          = (int)model.FriendRequestPendingId;
                model.RelationshipNotification = _uow.RelationshipNotifications.GetAll()
                                                 .Where(rn => rn.FriendRequestId == model.FriendRequestPendingId)
                                                 .ProjectTo <RelationshipNotificationModel>()
                                                 .FirstOrDefault();
            }

            if (model.IsFriendRequestSent)
            {
                model.FriendRequestId          = (int)model.FriendRequestSentId;
                model.RelationshipNotification = _uow.RelationshipNotifications.GetAll()
                                                 .Where(rn => rn.FriendRequestId == model.FriendRequestSentId)
                                                 .ProjectTo <RelationshipNotificationModel>()
                                                 .FirstOrDefault();
            }

            _svcContainer.UserSvc.GetUserPontsIntArray(model);
        }
        private bool HasUpdatePermission(QuizzerModel model)
        {
            if (model.Id == SvcContainer.UserSvc.GetCurrentUser().Id)
            {
                return(true);
            }
            if (SvcContainer.UserSvc.IsDependent(model.Id))
            {
                return(true);
            }

            return(false);
        }
示例#4
0
        public void UpdateModel(QuizzerModel model, int quizzerId)
        {
            SetAge(model);

            if (model.Id == _currentUser.Id)
            {
                model.IsQuizzmate = true;
            }

            if (_svcContainer.UserSvc.IsDependent(model.Id))
            {
                model.IsQuizzmate = true;
            }

            if (model.IsQuizzmate == false)
            {
                model.UserFullName = "";
            }
        }