예제 #1
0
        public async Task <IActionResult> Post([FromBody] Member member)
        {
            GenericResult result = null;

            if (!ModelState.IsValid)
            {
                result = new GenericResult()
                {
                    Succeeded = false,
                    Message   = "Dữ liệu không hợp lệ"
                };
                return(new OkObjectResult(result));
            }

            Member mem = new Member()
            {
                Name = member.Name
            };

            _memRepo.Add(mem);

            try
            {
                _memRepo.Commit();
            }
            catch (DbUpdateException ex)
            {
                result = new GenericResult()
                {
                    Succeeded = false,
                    Message   = $"{ex.Message}"
                };
                return(new OkObjectResult(result));
            }

            result = new GenericResult()
            {
                Succeeded = true,
                Message   = $"{mem.Name} thêm thành công"
            };
            return(new OkObjectResult(result));
        }
예제 #2
0
        public IActionResult Create(string userId, [FromBody] MemberViewModel member)
        {
            try
            {
                var userDB = _userRepository.GetSingle(userId);
                if (userDB == null)
                {
                    return(NotFound("NotFound"));
                }
                var memberDB = _memberRepository.GetSingle(member.Id);
                if (memberDB != null)
                {
                    return(NotFound("중복"));
                }

                var newMember = new Member
                {
                    Id        = member.Id,
                    UserId    = userId,
                    reinforce = member.reinforce
                };


                _memberRepository.Add(newMember);
                _memberRepository.Commit();
                _userRepository.Commit();

                MemberViewModel memberVM = Mapper.Map <Member, MemberViewModel>(newMember);

                return(new OkObjectResult(memberVM));
            }

            catch (Exception ex)
            {
                return(NotFound(ex));
            }
        }
예제 #3
0
        public void Save(Model.Member member)
        {
            memberRepository.Add(member);

            memberRepository.Commit();
        }