Exemplo n.º 1
0
        public JsonResult RevertFile(Guid guid)
        {
            string res;

            MemoryStream memstream = new MemoryStream();

            Request.InputStream.CopyTo(memstream);
            memstream.Position = 0;
            using (StreamReader reader = new StreamReader(memstream))
            {
                res = reader.ReadToEnd();
            }

            res = res.Remove(res.Length - 1);
            string filename = res.Substring(1);

            string source = Request.MapPath($"/App_Data/{Rep_CodeGroup.Get_CodeNameWithGUID(guid)}/{filename}");

            if (System.IO.File.Exists(source))
            {
                System.IO.File.Delete(source);
            }

            return(Json(true));
        }
Exemplo n.º 2
0
        public JsonResult SaveFile(Guid guid)
        {
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    file.SaveAs(Server.MapPath($"/App_Data/{Rep_CodeGroup.Get_CodeNameWithGUID(guid)}/{file.FileName}"));
                    return(Json(file.FileName));
                }
            }

            return(Json(false));
        }
Exemplo n.º 3
0
        public ActionResult CreateQuestion(Model_QuestionCreate model)
        {
            if (ModelState.IsValid)
            {
                Tbl_Question q = new Tbl_Question();
                q.Question_ERID        = model.ExamID;
                q.Question_Title       = model.Title;
                q.Question_TypeCodeID  = Rep_CodeGroup.Get_CodeIDWithGUID(model.Type);
                q.Question_GroupCodeID = Rep_CodeGroup.Get_CodeIDWithGUID(model.Group);
                //Question_ResponseID = Rep_CodeGroup.Get_CodeIDWithGUID(model.Response);
                q.Question_Mark         = model.Mark;
                q.Question_Order        = db.Tbl_Question.Any() ? db.Tbl_Question.OrderByDescending(x => x.Question_Order).First().Question_Order : 1;
                q.Question_CreationDate = q.Question_ModifiedDate = DateTime.Now;

                Tbl_Response p1 = new Tbl_Response();
                p1.Response_QuestionID = q.Question_ID;
                p1.Response_TypeCodeID = Rep_CodeGroup.Get_CodeIDWithGUID(model.Type);
                p1.Response_Title      = model.Filepond1;
                p1.Response_Order      = db.Tbl_Response.Any(x => x.Response_QuestionID.Equals(q.Question_ID)) ? db.Tbl_Question.OrderByDescending(x => x.Question_Order).First().Question_Order : 1;

                //p1.Tbl_Question = q;

                Tbl_Response p2 = new Tbl_Response();
                p1.Response_QuestionID = q.Question_ID;
                p1.Response_TypeCodeID = Rep_CodeGroup.Get_CodeIDWithGUID(model.Type);
                p1.Response_Title      = model.Filepond2;
                p1.Response_Order      = db.Tbl_Response.Any(x => x.Response_QuestionID.Equals(q.Question_ID)) ? db.Tbl_Question.OrderByDescending(x => x.Question_Order).First().Question_Order : 1;

                Tbl_Response p3 = new Tbl_Response();
                p1.Response_QuestionID = q.Question_ID;
                p1.Response_TypeCodeID = Rep_CodeGroup.Get_CodeIDWithGUID(model.Type);
                p1.Response_Title      = model.Filepond3;
                p1.Response_Order      = db.Tbl_Response.Any(x => x.Response_QuestionID.Equals(q.Question_ID)) ? db.Tbl_Question.OrderByDescending(x => x.Question_Order).First().Question_Order : 1;

                Tbl_Response p4 = new Tbl_Response();
                p1.Response_QuestionID = q.Question_ID;
                p1.Response_TypeCodeID = Rep_CodeGroup.Get_CodeIDWithGUID(model.Type);
                p1.Response_Title      = model.Filepond4;
                p1.Response_Order      = db.Tbl_Response.Any(x => x.Response_QuestionID.Equals(q.Question_ID)) ? db.Tbl_Question.OrderByDescending(x => x.Question_Order).First().Question_Order : 1;

                db.Tbl_Response.Add(p1);
                db.Tbl_Response.Add(p2);
                db.Tbl_Response.Add(p3);
                db.Tbl_Response.Add(p4);

                switch (Rep_CodeGroup.Get_CodeNameWithGUID(model.Response))
                {
                case "1":
                    q.Question_ResponseID = p1.Response_ID;
                    break;

                case "2":
                    q.Question_ResponseID = p2.Response_ID;
                    break;

                case "3":
                    q.Question_ResponseID = p3.Response_ID;
                    break;

                case "4":
                    q.Question_ResponseID = p4.Response_ID;
                    break;

                default:
                    break;
                }

                db.Entry(q).State = EntityState.Modified;

                if (Convert.ToBoolean(db.SaveChanges() > 0))
                {
                    TempData["TosterState"]   = "success";
                    TempData["TosterType"]    = TosterType.Maseage;
                    TempData["TosterMassage"] = "عملیات با موفقیت انجام شد";

                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData["TosterState"]   = "error";
                    TempData["TosterType"]    = TosterType.Maseage;
                    TempData["TosterMassage"] = "عملیات با موفقیت انجام نشد";

                    return(RedirectToAction("Details"));
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }