public ActionResult Add([FromBody] MemberLoginDto memberLogin) { try { var newMember = _dal.CreateMemberLogin(memberLogin); var memberLoginContract = _mapper.Map<MemberLoginDto>(newMember); return memberLogin != null ? (ActionResult) Accepted(memberLoginContract) : BadRequest("Unable to add"); } catch (Exception e) { return BadRequest(e); } }
public MemberLogin CreateMemberLogin(MemberLoginDto memberLogin) { using (var transaction = _context.Database.BeginTransaction()) { try { var memberShip = new MembershipType() { MembershipTypeName = "Individual" }; var newMember = new Member { FirstName = memberLogin.FirstName, LastName = memberLogin.LastName, SignUpDate = DateTime.Now, Email = memberLogin.Username, MembershipType = memberShip }; var createdMember = _context.Member.Add(newMember); var savedMember = _context.SaveChanges(); var newMemberLogin = new MemberLogin { Username = memberLogin.Username, Password = memberLogin.Password, CreatedAt = DateTime.Now }; _context.MemberLogin.Add(newMemberLogin); var createdMemberLogin = _context.SaveChanges(); transaction.Commit(); return(createdMemberLogin > 0 ? newMemberLogin : null); } catch (Exception) { throw; } } }