示例#1
0
        public async Task <ActionResult <Bill> > AddNewBill([FromBody] Bill bill)
        {
            dbContext.Add(bill);
            await dbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetAllBills), new {}, bill));
        }
        public async Task <IActionResult> PutBillType(int id, BillType billType)
        {
            if (id != billType.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("bill_id,date_generated,due_date,cust_ids,cust_id,premise_id,address,amount,status")] Bill_Information bill_Information)
        {
            if (ModelState.IsValid)
            {
                JPSUser data = await userManager.FindByIdAsync(bill_Information.cust_id);

                bill_Information.premise_id = data.premise_number;

                var address = await _context.PREMISE_DETAILS.FirstOrDefaultAsync(m => m.ID == "PREPJPS200");

                bill_Information.address = address.LOCATION_ADDRESS;

                BillDatabaseModel model = new BillDatabaseModel
                {
                    address        = bill_Information.address,
                    amount         = bill_Information.amount,
                    bill_id        = bill_Information.bill_id,
                    cust_id        = bill_Information.cust_id,
                    date_generated = bill_Information.date_generated,
                    due_date       = bill_Information.due_date,
                    premise_id     = bill_Information.premise_id,
                    status         = bill_Information.status
                };

                _context.Bill_Information.Add(model);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bill_Information));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("NumberBill,Date,Subtotal,Iva,Total,SupplierID")] BillPurchase billPurchase)
        {
            if (ModelState.IsValid)
            {
                _context.Add(billPurchase);
                await _context.SaveChangesAsync();

                //Save Detail
                var rows = Request.Form["list_detalle"].ToString().Split(',').ToList();
                foreach (string number in rows)
                {
                    var idProduct = Convert.ToInt64(Request.Form["id" + number].ToString());
                    var product   = _context.Product.Where(p => p.ID == idProduct).SingleOrDefault();
                    product.Stock = product.Stock + Convert.ToInt32(Request.Form["ca" + number].ToString());

                    _context.Product.Update(product);
                    _context.SaveChanges();

                    //Next Feature: Add description
                    //Save DetailMovement Table
                    var objectDetailMovement = new DetailMovement();
                    objectDetailMovement.ProductID = product.ID;
                    objectDetailMovement.Type      = 0; // entry product
                    objectDetailMovement.Amount    = Convert.ToInt32(Request.Form["ca" + number].ToString());
                    objectDetailMovement.UnitPrice = Convert.ToDecimal(Request.Form["pu" + number].ToString().Replace(".", ","));
                    objectDetailMovement.Stock     = product.Stock;

                    _context.DetailMovement.Add(objectDetailMovement);
                    _context.SaveChanges();

                    //Fixme: Update Cost Price
                    if (objectDetailMovement.UnitPrice > product.CostPrice)
                    {
                        product.CostPrice = objectDetailMovement.UnitPrice;
                        _context.Product.Update(product);
                        _context.SaveChanges();
                    }

                    //Save DetailBillPurchase
                    var objectDetailBillPurchase = new DetailBillPurchase();
                    objectDetailBillPurchase.BillPurchaseID   = billPurchase.ID;
                    objectDetailBillPurchase.DetailMovementID = objectDetailMovement.ID;
                    _context.DetailBillPurchase.Add(objectDetailBillPurchase);

                    _context.SaveChanges();
                    System.Diagnostics.Debug.WriteLine("IDDetailMovement: ", objectDetailMovement.ID);


                    //System.Diagnostics.Debug.WriteLine("Nombre: "+Request.Form["no"+number].ToString());
                }
                //System.Diagnostics.Debug.WriteLine("REQUEST: " + rows.Count);

                return(RedirectToAction("Index"));
            }
            ViewData["SupplierID"] = new SelectList(_context.Supplier, "ID", "ID", billPurchase.SupplierID);
            return(View(billPurchase));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("ID,ROW_ID,SUB_ID,LOCATION_ADDRESS")] PREMISE_DETAILS pREMISE_DETAILS)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pREMISE_DETAILS);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pREMISE_DETAILS));
        }
        public async Task <IActionResult> Create([Bind("Id,TypeID,Value,CreatedAt")] BillMeasure billMeasure)
        {
            if (ModelState.IsValid)
            {
                _context.Add(billMeasure);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TypeID"] = new SelectList(_context.BillTypes, "Id", "Name", billMeasure.TypeID);
            return(View(billMeasure));
        }
示例#7
0
        public async Task <ActionResult <BillModel> > PostBillModel(BillModel billModel)
        {
            try
            {
                var currentYear     = DateTime.Now.Year;
                var firstDateOfYear = new DateTime(currentYear, 1, 1);
                if (String.IsNullOrEmpty(billModel.Name))
                {
                    return(BadRequest(ErrorMessages.NameRequired));
                }
                else if (billModel.OriginalValue < 0)
                {
                    return(BadRequest(ErrorMessages.OriginalValueMustBePositive));
                }
                else if (billModel.DueDate < firstDateOfYear)
                {
                    return(BadRequest($"{ErrorMessages.InvalidDueDate}{currentYear}"));
                }
                _context.Bills.Add(billModel);
                var persisted = await _context.SaveChangesAsync();

                if (persisted > 0)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest(ErrorMessages.DataNotPersisted));
                }
            } catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#8
0
        public async Task <IActionResult> Create([Bind("Ruc,Name,City,Address,Phone,NameContactPerson,SkypeUserContactPerson")] Supplier supplier)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(supplier);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException ex)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
                Console.WriteLine("Error Create Product", ex);
            }

            return(View(supplier));
        }
        public async Task <IActionResult> Create([Bind("Code,Barcode,Name,CostPrice,Utility,SalePrice,Stock,State,CategoryID")] Product product)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(product);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                ViewData["CategoryID"] = new SelectList(_context.Category, "ID", "ID", product.CategoryID);
            }
            catch (DbUpdateException ex)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
                Console.WriteLine("Error Create Product", ex);
            }

            return(View(product));
        }
示例#10
0
 static async Task SeedBillContext(BillContext context, IServiceProvider services)
 {
     context.EnsureEnumeration <BillStatus>();
     await context.SaveChangesAsync();
 }
示例#11
0
 public async Task CreateClient(Client client)
 {
     db.Clients.Add(client);
     await db.SaveChangesAsync();
 }
示例#12
0
 public async Task CreateCompany(Company company)
 {
     db.Companies.Add(company);
     await db.SaveChangesAsync();
 }