コード例 #1
0
ファイル: SqlBadge.cs プロジェクト: shimanto7710/review-apis
        public BadgeModel UpdateBadge(int id, BadgeModel BadgeModel)
        {
            var badge = _dbReference.Badge.Find(id);

            if (badge != null)
            {
                if (BadgeModel.Name != null)
                {
                    badge.Name = BadgeModel.Name;
                }

                if (BadgeModel.CreatedAt != null)
                {
                    badge.CreatedAt = BadgeModel.CreatedAt;
                }

                if (BadgeModel.Point != 0)
                {
                    badge.Point = BadgeModel.Point;
                }

                _dbReference.Update(badge);
                _dbReference.SaveChangesAsync();
                return(badge);
            }

            return(BadgeModel);
        }
コード例 #2
0
        public UserModel UpdateUser(int id, UserModel userModel)
        {
            var user = _dbReference.User.Find(id);

            if (user != null)
            {
                if (userModel.Email != null)
                {
                    user.Email = userModel.Email;
                }
                if (userModel.Name != null)
                {
                    user.Name = userModel.Name;
                }
                if (userModel.Sex != 0)
                {
                    user.Sex = userModel.Sex;
                }

                if (userModel.Dp != null)
                {
                    user.Dp = userModel.Dp;
                }

                if (userModel.CreatedAt != null)
                {
                    user.CreatedAt = userModel.CreatedAt;
                }
                if (userModel.PhoneNumber != null)
                {
                    user.PhoneNumber = userModel.PhoneNumber;
                }

                if (userModel.UserType != 0)
                {
                    user.UserType = userModel.UserType;
                }
                if (userModel.IsFirstTime != false)
                {
                    user.IsFirstTime = userModel.IsFirstTime;
                }

                if (userModel.FirebaseKey != null)
                {
                    user.FirebaseKey = userModel.FirebaseKey;
                }
                if (userModel.BadgeId != 0)
                {
                    user.BadgeId = userModel.BadgeId;
                }


                _dbReference.Update(user);
                _dbReference.SaveChangesAsync();
                return(user);
            }

            return(userModel);
        }