Пример #1
0
        public ActionResult Edit(long id = 0)
        {
            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);

            if (tfile != null)
            {
                var bencana = (from table in db.t_report
                               join table2 in db.t_file
                               on table.report_id equals table2.file_parent
                               where table.report_id == id && table2.file_category == "Bencana"
                               select new admin.Models.BencanaCreate
                {
                    report_id = table.report_id,
                    report_author = table.report_author,
                    report_content = table.report_content,
                    report_time = table.report_time,
                    address = table.address,
                    phone = table.phone,
                    wil_id = table.wil_id
                }).FirstOrDefault();

                ViewBag.wilayah = new SelectList((from table in db.t_wilayah where table.wil_type == "Kelurahan" select table).ToList(), "wil_id", "wil_name");
                if (bencana == null)
                {
                    return(HttpNotFound());
                }

                return(View(bencana));
            }
            else
            {
                var bencana = (from table in db.t_report
                               where table.report_id == id
                               select new admin.Models.BencanaCreate
                {
                    report_id = table.report_id,
                    report_author = table.report_author,
                    report_content = table.report_content,
                    report_time = table.report_time,
                    address = table.address,
                    phone = table.phone,
                    wil_id = table.wil_id
                }).FirstOrDefault();

                ViewBag.wilayah = new SelectList((from table in db.t_wilayah where table.wil_type == "Kelurahan" select table).ToList(), "wil_id", "wil_name");
                if (bencana == null)
                {
                    return(HttpNotFound());
                }

                return(View(bencana));
            }
        }
Пример #2
0
        public ActionResult Edit(long id = 0)
        {
            var    id_file = (from table in db.t_file where table.file_parent == id && table.file_category == "ProsedurFile" select table.file_id).FirstOrDefault();
            t_file tfile   = db.t_file.Find(id_file);

            if (tfile != null)
            {
                var prosedur = (from table in db.t_content
                                join table2 in db.t_file
                                on table.content_id equals table2.file_parent
                                where table.content_id == id && table2.file_category == "ProsedurFile"
                                select new admin.Models.ContentCreate
                {
                    content_id = table.content_id,
                    content = table.content,
                    content_name = table.content_name,
                    content_time = table.content_time,
                    content_type = table.content_type,
                    url = table.url,
                    user_id = table.user_id
                }).FirstOrDefault();

                if (prosedur == null)
                {
                    return(HttpNotFound());
                }

                return(View(prosedur));
            }
            else
            {
                var prosedur = (from table in db.t_content
                                where table.content_id == id
                                select new admin.Models.ContentCreate
                {
                    content_id = table.content_id,
                    content = table.content,
                    content_name = table.content_name,
                    content_time = table.content_time,
                    content_type = table.content_type,
                    url = table.url,
                    user_id = table.user_id
                }).FirstOrDefault();

                if (prosedur == null)
                {
                    return(HttpNotFound());
                }

                return(View(prosedur));
            }
        }
Пример #3
0
        public ActionResult Edit(int id, admin.Models.ContentCreate t_content)
        {
            if (ModelState.IsValid)
            {
                var       id_file   = (from table in db.t_file where table.file_parent == id && table.file_category == "ProsedurFile" select table.file_id).FirstOrDefault();
                t_file    tfile     = db.t_file.Find(id_file);
                var       id_gambar = (from table in db.t_file where table.file_parent == id && table.file_category == "ProsedurGambar" select table.file_id).FirstOrDefault();
                t_file    tgambar   = db.t_file.Find(id_gambar);
                t_content content   = db.t_content.Find(id);
                var       valid     = 0;
                var       valid2    = 0;

                using (var konten = new db_esosEntities())
                {
                    content.content_name = t_content.content_name;
                    content.content_type = "Prosedur";
                    content.content      = t_content.content;
                    content.user_id      = (from table in konten.users where table.username == User.Identity.Name select table.id_user).FirstOrDefault();
                    content.content_time = DateTime.Now;
                    content.url          = "kosong";

                    var createFile   = db.t_file.Create();
                    var createGambar = db.t_file.Create();

                    if (t_content.file != null)
                    {
                        if (t_content.file.ContentLength < 3048000)
                        {
                            var fileName = Path.GetFileName(t_content.file.FileName);
                            var ex       = Path.GetExtension(fileName);
                            if (ex == ".pdf" || ex == ".ppt" || ex == ".pptx" || ex == ".xls" || ex == ".xlsx" || ex == ".doc" || ex == ".docx")
                            {
                                var path = Path.Combine(Server.MapPath("~/Content/Document"), fileName);
                                t_content.file.SaveAs(path);



                                createFile.file_category = "ProsedurFile";
                                createFile.file_location = path;
                                createFile.file_name     = fileName;
                                createFile.file_parent   = id;
                                createFile.file_title    = fileName;
                                createFile.file_url      = "~/Content/Document/" + fileName;
                                createFile.mime_type     = ex;
                                createFile.user_id       = (from table in db.users where table.username == User.Identity.Name select table.id_user).FirstOrDefault();
                                valid = 1;
                            }
                            else
                            {
                                ModelState.AddModelError("", "File harus berformat (.pdf/.ppt/.pptx/.xls/.xlsx/.doc/.docx)");
                                return(View(t_content));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Ukuran file tidak boleh lebih dari 3 MB");
                            return(View(t_content));
                        }
                    }

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



                                createGambar.file_category = "ProsedurGambar";
                                createGambar.file_location = path;
                                createGambar.file_name     = fileName;
                                createGambar.file_title    = fileName;
                                createGambar.file_url      = "~/Content/Image/" + fileName;
                                createGambar.mime_type     = ex;
                                createGambar.user_id       = (from table in db.users where table.username == User.Identity.Name select table.id_user).FirstOrDefault();
                                createGambar.file_parent   = id;
                                valid2 = 1;
                            }
                            else
                            {
                                ModelState.AddModelError("", "Gambar harus berformat (.jpg)");
                                return(View(t_content));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Ukuran gambar tidak boleh lebih dari 2 MB");
                            return(View(t_content));
                        }
                    }

                    db.SaveChanges();

                    if (valid == 1)
                    {
                        db.t_file.Add(createFile);
                        db.SaveChanges();

                        if (tfile != null)
                        {
                            db.t_file.Remove(tfile);
                            db.SaveChanges();
                        }
                    }

                    if (valid2 == 1)
                    {
                        db.t_file.Add(createGambar);
                        db.SaveChanges();

                        if (tgambar != null)
                        {
                            db.t_file.Remove(tgambar);
                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }
            }
            return(View(t_content));
        }
Пример #4
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));
            }
        }
Пример #5
0
        public ActionResult EditConfirmed(int id, admin.Models.BeritaCreate model)
        {
            t_news t_news = db.t_news.Find(id);
            var    file   = (from table in db.t_file where table.file_parent == id select table.file_id).FirstOrDefault();
            t_file t_file = db.t_file.Find(file);

            if (ModelState.IsValid)
            {
                using (var news = new db_esosEntities())
                {
                    var valid      = 0;
                    var create     = news.t_news.Create();
                    var createFile = news.t_file.Create();

                    create.user_id       = (from table in db.users where table.username == User.Identity.Name select table.id_user).FirstOrDefault();
                    create.news_date     = (from table in db.t_news where table.news_id == t_news.news_id select table.news_date).FirstOrDefault();
                    create.news_title    = model.news_title;
                    create.news_content  = model.news_content;
                    create.news_status   = model.news_status;
                    create.news_modified = DateTime.Now;
                    create.news_parent   = t_news.news_id;
                    create.news_type     = model.news_type;
                    create.news_url      = "Kosong";
                    create.news_category = model.news_category;

                    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);

                                createFile.file_category = "Berita";
                                createFile.file_location = path;
                                createFile.file_name     = fileName;
                                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();
                                valid = 1;
                            }
                            else
                            {
                                ModelState.AddModelError("", "Gambar harus berformat (.jpg)");
                                ViewBag.news_category = new SelectList(db.t_news_category.ToList(), "news_category_id", "category_title");
                                return(View(t_news));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Ukuran gambar tidak boleh lebih dari 2 MB");
                            ViewBag.news_category = new SelectList(db.t_news_category.ToList(), "news_category_id", "category_title");
                            return(View(t_news));
                        }
                    }
                    else
                    {
                        if (file != 0)
                        {
                            valid = 2;
                        }
                    }

                    db.t_news.Add(create);
                    db.SaveChanges();

                    t_news.news_status = "tidak_aktif";
                    db.SaveChanges();

                    if (valid == 1)
                    {
                        createFile.file_parent = (from table in db.t_news select table.news_id).Max();
                        db.t_file.Add(createFile);
                        db.SaveChanges();
                    }
                    else if (valid == 2)
                    {
                        t_file.file_parent = (from table in db.t_news select table.news_id).Max();
                        db.SaveChanges();
                    }

                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ViewBag.news_category = new SelectList(db.t_news_category.ToList(), "news_category_id", "category_title");
                return(View(t_news));
            }
        }