Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("FlagID,Comments,IsActive,MedicalDeviceID,Name,Problem,Warehouse,ReviewedBy,DateSubmitted,DateReviewed")] Flag flag, int id)
        {
            flag.MedicalDeviceID = id;
            flag.ReviewedBy      = "";
            flag.IsActive        = true;
            flag.DateSubmitted   = DateTime.UtcNow;
            flag.DateReviewed    = DateTime.MinValue;

            if (flagExists(id).Any())
            {
                ViewBag.Error = "A problem has already been reported for this item and it is under review.";
            }
            else if (ModelState.IsValid || id != 0)
            {
                _context.Add(flag);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new RouteValueDictionary(
                                            new { controller = "medicaldevices", action = "Index" })));
            }
            else
            {
                ViewBag.Error = "No Medical Device ID found or state is invalid.";
            }
            return(View(flag));
        }
        public async Task <IActionResult> AdminCreate([Bind("ID,Barcode,BinID,Brand,CreatedBy,Description,IsApproved,Manufacturer,PhotoUrl,Name,Warehouse,DateSubmitted")] MedicalDevice medicalDevice, IFormFile file)
        {
            medicalDevice.PhotoUrl      = "";
            medicalDevice.CreatedBy     = "*****@*****.**";
            medicalDevice.Name          = "Joy Carlson";
            medicalDevice.Warehouse     = "Denver";
            medicalDevice.DateSubmitted = DateTime.UtcNow;
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    var uploads = Path.Combine(_environment.WebRootPath, "uploads");
                    if (file.Length > 0)
                    {
                        using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }
                        medicalDevice.PhotoUrl = "uploads" + '/' + file.FileName;
                    }
                }
                medicalDevice.CreatedBy  = User.Identity.Name;
                medicalDevice.IsApproved = true;
                _context.Add(medicalDevice);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            PopulateBinsDropDownList(medicalDevice.BinID);
            return(View(medicalDevice));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("BinID,BinNumber,InUse,Name")] Bin bin)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bin);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(bin));
        }