예제 #1
0
        public ActionResult Create(ProcurementAndTenderModels procurementAndTenderModels,
                                   HttpPostedFileBase fileITReference)
        {
            ViewBag.error = "";
            allViewbags();

            if (ModelState.IsValid)
            {
                try
                {
                    db.ProcurementAndTenderModels.Add(procurementAndTenderModels);
                    db.SaveChanges();
                }
                catch (SqlException e)
                {
                    if (e.ErrorCode == 2601)
                    {
                        Response.Write("Student already registered!");
                        return(View(procurementAndTenderModels));
                    }
                }
                catch (DbUpdateException ex)
                {
                    var sqlException = ex.InnerException.InnerException as SqlException;
                    if (sqlException != null && sqlException.Number == 2627)
                    {
                        //Response.Write("LeterNo already registered!");
                        ViewBag.error = "Record already registered!";
                        return(View(procurementAndTenderModels));
                    }
                }



                string subPath = "~/ProcurementAndTender/" + "ITRef" + "/" + procurementAndTenderModels.ID.ToString();
                bool   exists  = System.IO.Directory.Exists(Server.MapPath(subPath));



                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
                }
                check_file(fileITReference, procurementAndTenderModels, "ITRef", procurementAndTenderModels.ID);

                db.Set <ProcurementAndTenderModels>().AddOrUpdate(procurementAndTenderModels);
                //db.Entry(procurementAndTenderModels).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(procurementAndTenderModels));
        }