Esempio n. 1
0
        public async Task <IActionResult> Create(DrugSellViewModel drug)
        {
            if (ModelState.IsValid)
            {
                var std = new DrugSell()
                {
                    PatientName = drug.PatientName,
                    Total_Price = drug.Total_Amt,
                    Qty         = drug.Qty
                };
                _context.DrugSells.Add(std);

                await _context.SaveChangesAsync();

                List <DrugSellDrug> drugsellList = new List <DrugSellDrug>();

                foreach (DrugViewModel dm in drug.DrugItemList)
                {
                    drugsellList.Add(new DrugSellDrug()
                    {
                        DrugsellId = std.Id,
                        DrugId     = dm.DrugIdd
                    });
                }
                _context.AddRange(drugsellList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(drug));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Qty,Total_Price")] DrugSell drugSell)
        {
            if (id != drugSell.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(drugSell);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DrugSellExists(drugSell.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(drugSell));
        }