// To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Site).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SiteExists(Site.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.MedicationUnits.Add(MedicationUnit);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Medication = await _context.Medications.FindAsync(id);

            if (Medication != null)
            {
                _context.Medications.Remove(Medication);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            var invalidId = await _context.Sites.Where(x => x.ID == Site.ID).ToListAsync();

            if (invalidId.Count != 0)
            {
                InvalidId = "The Id is already used!";
                return(Page());
            }
            else
            {
                InvalidId = null;
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Sites.Add(Site);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Subject = await _context.Subjects.FirstOrDefaultAsync(m => m.ID == id);

            if (Subject == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            SubjectBuy.RequestDate = DateTime.Now.Date;

            await GetMedications((int)id);

            Medication = Medications.Where(x => x.Name.Trim().ToUpper().Equals(SubjectBuy.MedicationName.Trim().ToUpper())).First();
            var _medicationUnits = MedicationUnits.Where(x => x.MedicationId == Medication.ID).ToList();

            _medicationUnits = _medicationUnits.Where(x => x.SiteId == Subject.SiteId).ToList();

            int quantity = _medicationUnits.Sum(x => x.Quantity);

            if (quantity < SubjectBuy.Quantity)
            {
                QuantityError = "The specified quantity is not available!";
                return(Page());
            }
            else
            {
                QuantityError = null;
            }

            quantity = SubjectBuy.Quantity;

            int counter = 0;

            while (quantity > 0)
            {
                if (quantity > _medicationUnits[counter].Quantity)
                {
                    quantity -= _medicationUnits[counter].Quantity;
                    _medicationUnits[counter].Quantity = 0;
                }
                else
                {
                    _medicationUnits[counter].Quantity -= quantity;
                    quantity = 0;
                }

                counter++;
            }

            foreach (var medicationUnit in _medicationUnits)
            {
                _context.Attach(medicationUnit).State = EntityState.Modified;
            }

            _context.SubjectBuys.Add(SubjectBuy);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SubjectExists(Subject.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }