Exemple #1
0
        public async Task <IActionResult> PutTB_USER([FromRoute] string id, [FromBody] TB_USER tB_USER)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tB_USER.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(tB_USER).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TB_USERExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("ID,Ten")] LoaiSanPham loaiSanPham)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loaiSanPham);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(loaiSanPham));
        }
Exemple #3
0
        public async Task RegistrarDetalleFacturaUnProductoMinimo([FromBody] DetalleFactura detalleFactura)
        {
            _spContext.Registrar_DetalleFactura_Un_Producto_MinimoAsync(
                detalleFactura.FacturaId, detalleFactura.ProductoId, detalleFactura.Cantidad, detalleFactura.PrecioUnitario);

            await _spContext.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("ID,Ten,Hinh,Maloai")] SanPham sanPham, IFormFile ful)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sanPham);
                await _context.SaveChangesAsync();

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img", sanPham.ID + "." + ful.FileName.Split(".")
                                        [ful.FileName.Split(".").Length - 1]);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                sanPham.Hinh = sanPham.ID + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                _context.Update(sanPham);
                _ = await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["Maloai"] = new SelectList(_context.LoaiSanPham, "ID", "ID", sanPham.Maloai);
            return(View(sanPham));
        }
Exemple #5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var db   = new SPContext();
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var profile = new UserProfiles();
                    profile.UserID    = user.Id;
                    profile.FirstName = "..";
                    profile.LastName  = "..";
                    profile.Created   = DateTime.UtcNow.Ticks;

                    db.UserProfiles.Add(profile);
                    await db.SaveChangesAsync();


                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    await UserManager.AddToRoleAsync(user.Id, model.Roles);

                    // 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"));
                }

                ViewBag.Roles = new SelectList(db.Roles.Where(a => !a.Name.Contains("Admin")).ToList(), "Name", "Name");

                AddErrors(result);
            }

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