コード例 #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new Contact {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> CreateAsync(ContactItem contact)
        {
            var result = await _contactManager.CreateAsync(contact);

            if (!result.Succeeded)
            {
                return(this.OperationError(result));
            }

            return(CreatedAtAction(nameof(FindByIdAsync), contact));
        }
コード例 #3
0
        public async Task <ActionResult> Create(Contact newContact)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var mgr = new ContactManager();
                    await mgr.CreateAsync(newContact);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    throw new ArgumentException("Name is required.");
                }
            }
            catch
            {
                return(View(newContact));
            }
        }
コード例 #4
0
        public async Task Test1Async()
        {
            var     id    = Guid.NewGuid();
            var     id2   = Guid.NewGuid();
            Contact found = new Contact();

            Contact ct = new Contact()
            {
                ID       = id,
                Email    = "un imail",
                Name     = "Luis",
                LastName = "Tejeda"
            };

            ct.Address = new Address()
            {
                Street         = "Camino",
                ExternalNumber = "5150",
                InternalNumber = "803A",
                Location       = ""
            };

            Contact ct2 = new Contact()
            {
                ID       = id2,
                Email    = "un imail",
                Name     = "Alfredo",
                LastName = "Tejeda"
            };

            ct.Address = new Address()
            {
                Street         = "Camino",
                ExternalNumber = "5150",
                InternalNumber = "803A",
                Location       = ""
            };

            ContactManager mgr = new ContactManager();
            var            ser = JsonConvert.SerializeObject(new List <Contact>()
            {
                ct, ct2
            });
            await mgr.CreateAsync(new List <Contact>() { ct, ct2 }).ContinueWith(p =>
            {
                var contactFoundLoc = mgr.GetByIDAsync(id).Result;
                found = contactFoundLoc;
                Assert.NotNull(contactFoundLoc);


                var contactAgainRes = mgr.GetByMongoIDAsync(contactFoundLoc.MongoID).Result;
                var contactAgain    = contactAgainRes.FirstOrDefault();


                Assert.NotNull(contactAgain);
            }).ContinueWith(task =>
            {
                found.Name = "updated";
                mgr.UpdateAsync(new List <Contact>()
                {
                    found
                }).Wait();


                var contactFound = mgr.GetByIDAsync(id).Result;

                Assert.Equal("updated", contactFound.Name);


                var contactFound2 = mgr.GetByIDAsync(id2).Result;

                var res = mgr.DeleteByIDsAsync(new List <Guid>()
                {
                    contactFound.ID, contactFound2.ID
                }).Result;

                var contactFound3 = mgr.GetByIDAsync(id).Result;

                var contactFound4 = mgr.GetByIDAsync(id2).Result;
            });
        }
コード例 #5
0
 public async Task Post([FromBody] List <Contact> contacts)
 {
     ContactManager mgr = new ContactManager();
     await mgr.CreateAsync(contacts);
 }