예제 #1
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var cosElemente = await _context.CosElemente.FindAsync(id);

            _context.CosElemente.Remove(cosElemente);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> Create(Produs produs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(produs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(produs));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Nume,Parola,Creare,Email,Telefon")] Utilizatori utilizatori)
        {
            if (ModelState.IsValid)
            {
                _context.Add(utilizatori);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(utilizatori));
        }
예제 #4
0
        public async Task <IActionResult> CumparaAsync(int id)
        {
            var user = _context.Utilizatori.FirstOrDefault(x => x.Nume == Request.Cookies["LoggedUser"]);
            var cos  = new Cos();

            if (user == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else
            {
                cos = _context.Cos.FirstOrDefault(e => e.Status == "Draft" && e.UserId == user.Id);
            }

            if (cos == null)
            {
                cos        = new Cos();
                cos.Status = "Draft";
                cos.UserId = user.Id;
                cos.Creare = DateTime.Now;

                _context.Add(cos);
                await _context.SaveChangesAsync();
            }

            var cosElemente = new CosElemente
            {
                Cantitate = 1,
                ProdusId  = id,
                CosId     = cos.Id
            };

            _context.Add(cosElemente);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }