Example #1
0
        public ActionResult Edit(msformatksk msformatksk)
        {
            var cek = db.msformatksks.FirstOrDefault(x => x.dataBerkas == msformatksk.dataBerkas);

            if (cek == null)
            {
                if (ModelState.IsValid)
                {
                    msformatksk msformat = db.msformatksks.Find(msformatksk.idftksk);
                    foreach (var file in msformatksk.files)
                    {
                        if (file.ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var filePath = Path.Combine(Server.MapPath("~/Files"), fileName);
                            file.SaveAs(filePath);

                            msformat.nama       = msformatksk.nama;
                            msformat.dataBerkas = fileName.ToString();
                            msformat.modidate   = DateTime.Now;
                            msformat.modiby     = msformatksk.modiby;

                            db.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                    }
                }
                return(View(msformatksk));
            }
            else
            {
                ViewBag.Message = "BERKAS YANG ANDA MASUKAN SUDAH ADA";
                return(View(msformatksk));
            }
        }
Example #2
0
        public ActionResult Create(msformatksk msformatksk)
        {
            try
            {
                var cek = db.msformatksks.FirstOrDefault(x => x.dataBerkas == msformatksk.dataBerkas);
                if (cek == null)
                {
                    if (ModelState.IsValid)
                    {
                        foreach (var file in msformatksk.files)
                        {
                            if (file.ContentLength > 0)
                            {
                                var fileName = Path.GetFileName(file.FileName);
                                var filePath = Path.Combine(Server.MapPath("~/Files"), fileName);
                                file.SaveAs(filePath);

                                msformatksk.nama       = msformatksk.nama.ToString();
                                msformatksk.dataBerkas = fileName.ToString();
                                msformatksk.creadate   = DateTime.Now;
                                msformatksk.modidate   = DateTime.Now;
                                msformatksk.status     = 1;
                                msformatksk.creaby     = msformatksk.creaby.ToString();
                                msformatksk.modiby     = msformatksk.modiby.ToString();


                                db.msformatksks.Add(msformatksk);
                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                        }
                    }

                    return(View(msformatksk));
                }
                else
                {
                    ViewBag.Message = "FORMAT KESEKRETARIATAN YANG ANDA MASUKAN SUDAH ADA";
                    return(View(msformatksk));
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
        }
Example #3
0
        public ActionResult Delete(int id)
        {
            msformatksk msformatksk = db.msformatksks.Find(id);

            msformatksk.status = 0;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #4
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            msformatksk msformatksk = db.msformatksks.Find(id);

            if (msformatksk == null)
            {
                return(HttpNotFound());
            }
            return(View(msformatksk));
        }