public ActionResult Save(RegisterApplicationForm doc) { var entity = new sovadb001Entities0(); order norder = new order(); //entity.orders.Add(norder); int[] specComplexity = new int[doc.spec.Length + 1]; int i = 1; specComplexity[0] = (int)DataBase.GetSpecialization(doc.Language).complexity; documentSpecialization dc = new documentSpecialization(); dc.IdSpecialization = DataBase.GetSpecialization(doc.Language).IdSpecialization; entity.documentSpecializations.Add(dc); foreach (var spec in doc.spec) { specComplexity[i] = (int)DataBase.GetSpecialization(spec).complexity; i++; documentSpecialization ndocSpec = new documentSpecialization(); //ndocSpec.order = norder; ndocSpec.IdOrder = norder.IdOrder; // ndocSpec.specialization = DataBase.GetSpecialization(spec); ndocSpec.IdSpecialization = DataBase.GetSpecialization(spec).IdSpecialization; //DataBase.AddDocSpec(ndocSpec); entity.documentSpecializations.Add(ndocSpec); // norder.documentSpecializations.Add(ndocSpec); } norder.dateOfCompletion = DateTime.Now; norder.name = doc.name; norder.description = doc.description; norder.deadline = doc.deadline; user iduser = auth.AuthHelper.GetUser(HttpContext); if (iduser.roleid == 1 && doc.userId != 0) { norder.idUser = doc.userId; } else { norder.idUser = auth.AuthHelper.GetUser(HttpContext).Id; } norder.isDone = false; norder.inProgress = false; //DataBase.AddApplication(norder); entity.orders.Add(norder); entity.SaveChanges(); return(RedirectToAction("Index", "Home")); // } }
public ActionResult Apply(RegisterApplicationForm doc) { if (ModelState.IsValid) { if (doc.UploadedFiles != null && doc.UploadedFiles[0] != null) { if (!Directory.Exists(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name))) { Directory.CreateDirectory(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name)); } int i = 0; float priceOrder = 0; int[] specComplexity = new int[doc.spec.Length]; foreach (int spec in doc.spec) { specComplexity[i] = (int)DataBase.GetSpecialization(spec).complexity; } i = 0; List <double [, ]> nspecdocs = new List <double [, ]>(); foreach (var UploadedFile in doc.UploadedFiles) { bool img = false; string fileName = System.IO.Path.GetFileName(UploadedFile.FileName); const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); string nfilename = new string(Enumerable.Repeat(chars, 10).Select(s => s[random.Next(s.Length)]).ToArray()); nfilename += "." + fileName.Split('.')[1]; UploadedFile.SaveAs(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name) + "\\" + nfilename); //string result = TextParsing.ImgToFile(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name) + "\\" + nfilename, doc.Language); //if (result != null) //{ // img = true; // string nfilenameTranslate = new string(Enumerable.Repeat(chars, 10).Select(s => s[random.Next(s.Length)]).ToArray())+".txt"; // System.IO.File.WriteAllText(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name) + "\\" + nfilenameTranslate, result); // doc.translatefileNames[i] = nfilenameTranslate; //} //string filenameToCountSymbols; //if (doc.translatefileNames != null && doc.translatefileNames[i] != null) { filenameToCountSymbols = doc.translatefileNames[i]; } //else filenameToCountSymbols = nfilename; //int count = countSymbolsIndoc(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name) + "\\" + filenameToCountSymbols, filenameToCountSymbols.Split('.')[1]); //priceOrder += textPrice(specComplexity, count); //nspecdocs.Add( TextParsing.TextSpecialization(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name) + "\\" + filenameToCountSymbols,doc.Language)); //i++; } } return(View(doc)); } else { if (doc.UploadedFiles != null && doc.UploadedFiles[0] != null) { foreach (var UploadedFile in doc.UploadedFiles) { // string fileName = System.IO.Path.GetFileName(UploadedFile.FileName); //if(Directory.Exists(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name))&&System.IO.File.Exists(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name +"\\" +fileName))) // System.IO.File.Delete(Server.MapPath("~/Content/Temporary/" + auth.AuthHelper.GetUser(HttpContext).name +"\\" +fileName)); } } return(View("~/Views/Application/Register.cshtml", doc)); } //else return RedirectToAction("Register", "Application",doc); }