Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(long id)
        {
            t_report t_report = db.t_report.Find(id);

            db.t_report.Remove(t_report);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult Details(long id = 0)
        {
            t_report t_report = db.t_report.Find(id);
            var      wilayah  = (from table in db.t_report
                                 where table.report_id == id
                                 join table2 in db.t_wilayah
                                 on table.wil_id equals table2.wil_id
                                 select table2.wil_name).FirstOrDefault();

            ViewBag.wilayah = wilayah;
            var gambar = (from table in db.t_file where table.file_parent == id && table.file_category == "Bencana" select table.file_url).FirstOrDefault();

            ViewBag.gambar = gambar;
            if (t_report == null)
            {
                return(HttpNotFound());
            }
            return(View(t_report));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, admin.Models.BencanaCreate model)
        {
            if (ModelState.IsValid)
            {
                var      id_file = (from table in db.t_file where table.file_parent == id && table.file_category == "Bencana" select table.file_id).FirstOrDefault();
                t_file   tfile   = db.t_file.Find(id_file);
                t_report report  = db.t_report.Find(id);

                using (var bencana = new db_esosEntities())
                {
                    report.report_author  = model.report_author;
                    report.phone          = model.phone;
                    report.address        = model.address;
                    report.report_content = model.report_content;
                    report.report_time    = DateTime.Now;
                    report.wil_id         = model.wil_id;

                    if (model.gambar != null)
                    {
                        if (model.gambar.ContentLength < 2048000)
                        {
                            var fileName = Path.GetFileName(model.gambar.FileName);
                            var ex       = Path.GetExtension(fileName);
                            if (ex == ".jpg")
                            {
                                var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName);
                                model.gambar.SaveAs(path);

                                var createFile = db.t_file.Create();

                                createFile.file_category = "Bencana";
                                createFile.file_location = path;
                                createFile.file_name     = fileName;
                                createFile.file_parent   = id;
                                createFile.file_title    = fileName;
                                createFile.file_url      = "~/Content/Image/" + fileName;
                                createFile.mime_type     = ex;
                                createFile.user_id       = (from table in db.users where table.username == User.Identity.Name select table.id_user).FirstOrDefault();

                                db.t_file.Add(createFile);
                                db.SaveChanges();

                                if (tfile != null)
                                {
                                    db.t_file.Remove(tfile);
                                    db.SaveChanges();
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("", "Gambar harus berformat (.jpg)");
                                ViewBag.wilayah = new SelectList((from table in db.t_wilayah where table.wil_type == "Kelurahan" select table).ToList(), "wil_id", "wil_name");
                                return(View(model));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Ukuran gambar tidak boleh lebih dari 2 MB");
                            ViewBag.wilayah = new SelectList((from table in db.t_wilayah where table.wil_type == "Kelurahan" select table).ToList(), "wil_id", "wil_name");
                            return(View(model));
                        }
                    }

                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ViewBag.wilayah = new SelectList((from table in db.t_wilayah where table.wil_type == "Kelurahan" select table).ToList(), "wil_id", "wil_name");
                return(View(model));
            }
        }