Exemplo n.º 1
0
        public async Task <IActionResult> Edit(Guid id, [Bind(PKey.LFPram)] LostFound lostFound)
        {
            if (id != lostFound.Guid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    lostFound.UpdateTime = DateTime.Now;
                    lostFound.State      = LostFound.Lost.OreadyFound;
                    lostFound.FoundTime  = DateTime.Now;
                    context.Update(lostFound);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LostFoundExists(lostFound.Guid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(lostFound));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind(PKey.LFPram)] LostFound lostFound)
        {
            if (ModelState.IsValid)
            {
                lostFound.Guid = Guid.NewGuid();
                context.Add(lostFound);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lostFound));
        }
        public ActionResult Update(int id, string lostorfound, string item, string category, string color, string contactno, string note)
        {
            LostFound items = db.lostFounds.FirstOrDefault(b => b.LostFoundID == id);

            items.LostorFound       = lostorfound;
            items.LostFoundItem     = item;
            items.LostFoundCategory = category;
            items.LostFoundColor    = color;
            items.LostFoundPerson   = contactno;
            items.LostFoundNote     = note;

            db.SaveChanges();
            return(RedirectToAction("List"));
        }
        public ActionResult Add(string lostorfound, string item, string category, string color, string contactno, string note)
        {
            LostFound lostandfound = new LostFound();
            DateTime  now          = DateTime.Now;

            lostandfound.LostorFound       = lostorfound;
            lostandfound.LostFoundItem     = item;
            lostandfound.LostFoundDate     = now.ToString();
            lostandfound.LostFoundCategory = category;
            lostandfound.LostFoundColor    = color;
            lostandfound.LostFoundPerson   = contactno;
            lostandfound.LostFoundNote     = note;
            lostandfound.PatientID         = 1.ToString();
            db.lostFounds.Add(lostandfound);
            db.SaveChanges();
            return(RedirectToAction("List"));
        }
        public ActionResult Update(int id)
        {
            LostFound item = db.lostFounds.FirstOrDefault(b => b.LostFoundID == id);

            return(View(item));
        }
        //This function will add lost and found reports
        public ActionResult Add(string lostorfound, HttpPostedFileBase itempic, string item, string category, string color, string contactno, string note)
        {
            int    haspic       = 0;
            string picextension = "";
            string id           = User.Identity.GetUserId();

            if (itempic != null)
            {
                Debug.WriteLine("Something identified...");
                //checking to see if the file size is greater than 0 (bytes)
                if (itempic.ContentLength > 0)
                {
                    Debug.WriteLine("Successfully Identified Image");

                    var valtypes  = new[] { "jpeg", "jpg", "png", "gif" };
                    var extension = Path.GetExtension(itempic.FileName).Substring(1);

                    if (valtypes.Contains(extension))
                    {
                        try
                        {
                            //file name is the id of the image
                            string fn = id + "." + extension;

                            //get a direct file path to ~/Content/Pets/{id}.{extension}
                            string path = Path.Combine(Server.MapPath("~/Content/LostFoundImages/"), fn);

                            //save the file
                            itempic.SaveAs(path);
                            //if these are all successful then we can set these fields
                            haspic = 1;
                            //This will be in database to fetch and used to display photo on show page
                            picextension = fn;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("News Image was not saved successfully.");
                            Debug.WriteLine("Exception:" + ex);
                        }
                    }
                }
            }
            //Store details in lost and found table
            LostFound lostandfound = new LostFound();
            DateTime  now          = DateTime.Now;

            lostandfound.LostorFound       = lostorfound;
            lostandfound.LostFoundItem     = item;
            lostandfound.LostFoundDate     = now.ToString();
            lostandfound.LostFoundCategory = category;
            lostandfound.LostFoundColor    = color;
            lostandfound.LostFoundPerson   = contactno;
            lostandfound.LostFoundNote     = note;
            lostandfound.picextension      = picextension;
            //Stores patientID to associate with patient
            lostandfound.PatientID = id;
            db.lostFounds.Add(lostandfound);
            db.SaveChanges();
            return(RedirectToAction("List"));
            //return View();
        }