示例#1
0
        public ActionResult SaveMember(DetailViewModel viewModel)
        {
            if (!_memberService.IsUsernameAvailable(viewModel.Member.Username, viewModel.Member.MemberId))
            {
                ModelState.AddModelError("Member.Username", "Username is already being used. Try another.");
            }

            if (ModelState.IsValid)
            {
                var isEditMode = viewModel.Member.MemberId.GetValueOrDefault(0) > 0;

                if (isEditMode)
                {
                    _memberService.UpdateMember(viewModel.Member);
                }
                else
                {
                    var newId = _memberService.AddMember(viewModel.Member);
                    return(Detail(newId));
                }
            }

            if (!ModelState.IsValid && Request.IsAjaxRequest())
            {
                return(PartialView("Detail"));
            }

            return(Detail(viewModel.Member.MemberId));
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    //call MembersService to AddNewMember
                    _memberService.AddMember(
                        new ShoppingCart.Application.ViewModels.MemberViewModel()
                    {
                        Email     = Input.Email,
                        FirstName = Input.FirstName,
                        LastName  = Input.LastName
                    }

                        );

                    await _userManager.AddToRoleAsync(user, "User"); //default role is user

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
示例#3
0
 public void AddMember(string INSZ, string FirstName, string LastName, string street, string number, string postalCode, string City)
 {
     service.AddMember(INSZ, FirstName, LastName, street, number, postalCode, City);
     addview.Close();
     ClearAllMembers();
     LoadAllMembers();
 }
示例#4
0
 public void AddMember(string firstName, string street, string number, string postalCode,
                       string city, string INSS, string lastName)
 {
     service.AddMember(firstName, street, number, postalCode, city, INSS, lastName);
     addView.Close();
     ClearAllMembers();
     LoadAllMembers();
 }
 public IActionResult Create(Member member)
 {
     if (ModelState.IsValid)
     {
         _memberService.AddMember(member);
         return(RedirectToAction(nameof(Index)));
     }
     return(View());
 }
 public void Post([FromBody] Member member)
 {
     if (ModelState.IsValid)
     {
         _mservice.AddMember(member);
     }
     else
     {
         BadRequest(ModelState);
     }
 }
示例#7
0
        public ActionResult AddMember([FromBody] NewMember member)
        {
            var response = _memberService.AddMember(member);

            if (response == null)
            {
                return(BadRequest());
            }

            return(CreatedAtAction(nameof(GetMember), new { CardId = member.CardId }, response));
        }
        public IActionResult AddMember([FromBody] Member member)
        {
            var validator = new MemberValidator();

            if (validator.Validate(member).IsValid)
            {
                _memberService.AddMember(member);
                return(Ok());
            }
            return(BadRequest());
        }
示例#9
0
        public async Task <IActionResult> AddMember(MemberForCreation memberForCreation)
        {
            var member = _mapper.Map <User>(memberForCreation);

            member = await _memberService.AddMember(member);

            var MemberToReturn = _mapper.Map <UserForDetailedDto>(member);

            MemberToReturn.LibraryCardNumber = member.LibraryCard.Id;

            return(CreatedAtAction("GetUser", new { id = MemberToReturn.Id }, MemberToReturn));
        }
        public ActionResult Create(MemberVm vm)
        {
            try
            {
                var newMember = new Member();

                newMember.SSN  = vm.SSN;
                newMember.Name = vm.Name;
                _memberService.AddMember(newMember);
                return(RedirectToAction(nameof(Index)));
            }
            catch (DbException)
            {
                return(View());
            }
        }
示例#11
0
        public async Task <IActionResult> Create(MemberCreateVm vm)
        {
            if (ModelState.IsValid)
            {
                //Skapa ny Medlem
                var newMember = new Member();
                newMember.Name  = vm.Name;
                newMember.Email = vm.Email;

                memberservice.AddMember(newMember);

                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction("Error", "Home", ""));
        }
示例#12
0
 public ActionResult Register(Member member)
 {
     if (ModelState.IsValid)
     {
         if (member == null)
         {
             return(null);
         }
         else
         {
             Member member1 = _memberService.AddMember(member);
             return(RedirectToAction("ConfirmEmail", "Member", new { ID = member1.id }));
         }
     }
     return(null);
 }
示例#13
0
        public async Task <IActionResult> Create(MemberCreateVm vm)
        {
            if (ModelState.IsValid)
            {
                //Create new member
                var newMember = new Member();
                newMember.SSN  = vm.SSN;
                newMember.Name = vm.Name;

                memberService.AddMember(newMember);

                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction("Error", "Home", ""));
        }
示例#14
0
        public void Ensure_AddMember_Works(int institutionId)
        {
            var allMembers = new List <Member>();

            var newMember = new Member()
            {
                Id = 3, GivenName = "Dan", SurName = "Rather", InstitutionId = institutionId
            };

            _memberRepository.Setup(m => m.Insert(newMember)).Callback(() => allMembers.Add(newMember));
            _memberRepository.Setup(m => m.GetAll()).Returns(allMembers);

            _memberService.AddMember(newMember, institutionId);

            var actualMembers   = _memberService.GetAllMembersByInstitution(institutionId);
            var expectedMembers = allMembers.Where(x => x.InstitutionId == institutionId).ToList();

            Assert.AreEqual(actualMembers, Is.EquivalentTo(expectedMembers));
            Assert.AreEqual(expectedMembers.Count, 1);
        }
示例#15
0
        public ActionResult Create(MemberEditionViewModel model)
        {
            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("password", "Veuillez confirmer votre mot de passe.");
            }
            if (!string.IsNullOrEmpty(model.Password) && (model.Password == model.ConfirmPassword))
            {
                string position = "Member";
                if (model.IsAdmin)
                {
                    position = "Admin";
                }
                Member newMember = new Member()
                {
                    Title = model.Title, Fname = model.Fname, Lname = model.Lname, IsLive = model.IsLive, IsAdmin = model.IsAdmin, Email = model.Email, Position = position, PicturePath = model.PicturePath
                };
                newMember.Password = Utilities.PasswordHelper.HashPassword(model.Email, model.Password);
                if (model.Picture != null && model.Picture.Length != 0 && model.Picture.Length < 10485761)
                {
                    // string originalFilename = WebUtility.HtmlEncode(Path.GetFileName(model.Picture.FileName));
                    string contenttype = model.Picture.ContentType;
                    if (contenttype == "image/gif" || contenttype == "image/jpeg" || contenttype == "image/jpg" || contenttype == "image/png")
                    {
                        MemoryStream ms = new MemoryStream();
                        model.Picture.CopyTo(ms);
                        newMember.Picture = ms.ToArray();
                        newMember.PicType = contenttype;
                    }
                }

                Member member = _memberService.AddMember(newMember);
                if (member != null && member.ID > 0)
                {
                    return(RedirectToAction("Index", "Dashboard", null));
                }
            }


            return(View("Edition", model));
        }
示例#16
0
        public ActionResult Create(MemberCreateVm vm)
        {
            //vm.MemberStatusList = new SelectList(memberCardService.GetAllMemberCards(), "Id", "Member-Status");
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }
            {
                //Create new car
                var newMember = new MemberDetails();
                newMember.FirstName      = vm.FirstName;
                newMember.LastName       = vm.LastName;
                newMember.Adress         = vm.Adress;
                newMember.Age            = vm.Age;
                newMember.DriversLicense = vm.DriversLicense;
                newMember.MemberCardId   = vm.MemberCardId;


                memberService.AddMember(newMember);
                return(RedirectToAction(nameof(Index)));
            }
        }
示例#17
0
        public ActionResult <Member> PostMember(MemberDetailDto memberDetailDto)
        {
            var member = new Member
            {
                FirstName    = memberDetailDto.FirstName,
                LastName     = memberDetailDto.LastName,
                MemberSports = memberDetailDto.Sports.Select(s => new MemberSport
                {
                    SportId = s.Id
                }).ToList()
            };

            _memberService.AddMember(member);

            var memberDto = new MemberDto()
            {
                Id        = member.Id,
                FirstName = member.FirstName,
                LastName  = member.LastName
            };

            return(CreatedAtAction("GetMember", new { id = member.Id }, memberDto));
        }
示例#18
0
        public async Task <IActionResult> Add(Member member, int institutionId)
        {
            await _memberService.AddMember(member, institutionId);

            return(Ok(member));
        }
 public void Post([FromBody] MemberRegistrationInfo value)
 {
     memberService.AddMember(value);
 }
示例#20
0
 protected override int InsertInternal(Member value)
 {
     return(_memberService.AddMember(value));
 }