//CREATE /members
 public bool CreateMember(MemberCreate model)
 {
     var newMember = new Member()
     {
         Id        = model.Id,
         CreatedAt = DateTimeOffset.Now
     };
     {
         using (var ctx = new ApplicationDbContext())
         {
             ctx.Members.Add(newMember);
             return(ctx.SaveChanges() == 1);
         }
     }
 }
        public IHttpActionResult Post(MemberCreate member)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateMemberService();

            if (!service.CreateMember(member))
            {
                return(InternalServerError());
            }

            return(Ok("Member added!"));
        }
示例#3
0
        public bool CreateMember(MemberCreate model)
        {
            var entity = new Member()
            {
                OwnerID   = _userID,
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Location  = model.Location,
                FullName  = $"{model.FirstName} {model.LastName}"
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Members.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#4
0
        public ActionResult Create(MemberCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateMemberService();

            if (service.CreateMember(model))
            {
                TempData["SaveResult"] = "Member Added.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Member Could Not Be Made");
            return(View(model));
        }
示例#5
0
        //private readonly int _memberID;

        // public MemberService(int memberID)
        // {
        //_memberID = memberID;
        //}
        public bool CreateMember(MemberCreate model)
        {
            var entity = new Member
            {
                //MemberID = model.MemberID,
                DateJoined  = model.DateJoined,
                Name        = model.Name,
                Email       = model.Email,
                Address     = model.Address,
                PhoneNumber = model.PhoneNumber,
                LocationID  = model.LocationID
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Members.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }