Exemplo n.º 1
0
        public async Task <IActionResult> PutInvoiceElectro([FromRoute] int id, [FromBody] InvoiceElectro invoiceElectro)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != invoiceElectro.Id)
            {
                return(BadRequest());
            }

            _unitOfWork.Entry(invoiceElectro).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,InvoiceDate,ProviderName,Payment,Debt,Overpaid,PrevNumber,CurrentNumber,UserId,MonthId")] InvoiceElectro invoiceElectro)
        {
            if (id != invoiceElectro.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _unitOfWork.Update(invoiceElectro);
                    await _unitOfWork.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InvoiceElectroExists(invoiceElectro.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MonthId"] = new SelectList(_unitOfWork.Months.GetDbSet(), "Id", "Name", invoiceElectro.MonthId);
            //ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", invoiceElectro.UserId);
            ViewData["UserId"] = invoiceElectro.UserId;
            return(View(invoiceElectro));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,InvoiceDate,ProviderName,Payment,Debt,Overpaid,PrevNumber,CurrentNumber,UserId,MonthId")] InvoiceElectro invoiceElectro)
        {
            if (ModelState.IsValid)
            {
                _unitOfWork.Add(invoiceElectro);
                await _unitOfWork.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MonthId"] = new SelectList(_unitOfWork.Months.GetDbSet(), "Id", "Name", invoiceElectro.MonthId);
            //ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", invoiceElectro.UserId);
            ViewData["UserId"] = invoiceElectro.UserId;
            return(View(invoiceElectro));
        }