示例#1
0
        public JsonResult GetById(int id)
        {
            TB_M_Supplier supplier     = null;
            var           client       = new HttpClient();
            var           responseTask = client.GetAsync("http://localhost:2414/API/Suppliers/" + id);

            responseTask.Wait();
            var result = responseTask.Result;

            if (result.IsSuccessStatusCode)
            {
                var readTask = result.Content.ReadAsAsync <TB_M_Supplier>();
                readTask.Wait();
                supplier = readTask.Result;
            }
            else
            {
                // try to find something
            }

            return(Json(supplier, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //Add Role to User
                    UserManager.AddToRole(user.Id, "Supplier");

                    //Add Data Supplier
                    var supp = new TB_M_Supplier {
                        Email = model.Email, Name = model.Name, Address = model.Address, City = model.City, State = model.State, Country = model.Country, Zipcode = model.Zipcode
                    };
                    conn.TB_M_Supplier.Add(supp);
                    conn.SaveChanges();

                    //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", "Supplier"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }