Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("AutoId,Id,Name,ContactPerson,ContactNo,PhoneNo,VendorType,Type,Place,Dob,Gstno,Tinno,Panno,Cinno,AdhaarNo,OpeningBalance,OpeningBalanceType,OpeningBalanceDate,CreditLimit,CreditPeriod,CreditInterestRate,DebitInterestRate,CreatedDatetime,Photo,Remark,SuretyPerson,SuretyPersonContactNo,SuretyPersonAddress")] TblVendor tblVendor)
        {
            if (ModelState.IsValid)
            {
                var saved = false;
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _context.Add(tblVendor);
                        if (tblVendor.VendorType == "Customer")
                        {
                            _context.UpdateNextSequence(SequenceTable.tbl_Customer);
                        }
                        else if (tblVendor.VendorType == "Supplier")
                        {
                            _context.UpdateNextSequence(SequenceTable.tbl_Supplier);
                        }
                        else
                        {
                            _context.UpdateNextSequence(SequenceTable.tbl_vendor);
                        }

                        await _context.SaveChangesAsync();

                        saved = true;
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException(e.Message);
                    }
                    finally
                    {
                        if (saved)
                        {
                            transaction.Commit();
                        }
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Type"] = new SelectList(_context.TblVendorType, "Id", "Id", tblVendor.Type);

            return(View(tblVendor));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(
            [Bind(
                 "Id,Name,HsnSacNo,Type,MeasuringUnit,Manufacture,BarCode,ItemUniqueDescription,Supplier,Photo,UseBatchNo,UseMfgDate,UseExpiryDate,CreatedDatetime,Gst")]
            TblItems items, [Bind("OpeningStock")] int?openingStock)
        {
            if (ModelState.IsValid)
            {
                var saved = false;
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        _context.Add(items);
                        //await _context.SaveChangesAsync();


                        _context.UpdateNextSequence(SequenceTable.tbl_Items);
                        //TblSequence NewSequenceValue = Helper.GenericHelper.GetNextUpdatedData("tbl_Items");
                        //_context.Entry(NewSequenceValue).State = EntityState.Modified;
                        //await _context.SaveChangesAsync();

                        if (openingStock > 0)
                        {
                            TblItemStock tbl_ItemStock = new TblItemStock()
                            {
                                Id              = items.Id + "-" + Helper.GenericHelper.GetMaxValue("tbl_ItemStock") + "-1",
                                StockType       = "IN",
                                InvoiceNo       = "Opening Stock",
                                ItemId          = items.Id,
                                Qty             = openingStock,
                                CreatedDatetime = items.CreatedDatetime.ToString() ??
                                                  DateTime.Now.Date.ToString(CultureInfo.InvariantCulture)
                            };
                            _context.TblItemStock.Add(tbl_ItemStock);
                            //await _context.SaveChangesAsync();
                            _context.UpdateNextSequence(SequenceTable.tbl_ItemStock);
                        }


                        await _context.SaveChangesAsync();

                        saved = true;
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException(e.Message);
                    }
                    finally
                    {
                        if (saved)
                        {
                            transaction.Commit();
                        }
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Gst"]           = new SelectList(_context.TblGst, "Id", "Name", items.Gst);
            ViewData["MeasuringUnit"] = new SelectList(_context.TblItemUnits, "MeasurintUnitId", "MeasuringUnits",
                                                       items.MeasuringUnit);
            ViewData["Supplier"] = new SelectList(_context.TblVendor, "Id", "Name", items.Supplier);
            ViewData["Type"]     = new SelectList(_context.TblItemType, "ItemTypeId", "ItemType", items.Type);
            return(View(items));
        }