public ActionResult CommitDataCompleted(Submission result, string status) { ViewBag.Status = status; if (result != null) return View(result); else { ViewBag.errorMsg = "Error submitting your data. Please try again"; return View("Error"); } }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { //get submission from session var submission = (Submission)controllerContext.HttpContext.Session[_sessionKey]; if (submission == null) { submission = new Submission() { Status = "Initiated", SubmittingUser = controllerContext.HttpContext.User.Identity.Name }; controllerContext.HttpContext.Session[_sessionKey] = submission; } return submission; }
// // GET: /Submission/Create //create submission public ActionResult Create(int ticketId, Submission submission) { submission.TicketID = ticketId; return RedirectToAction("UploadFile", "Upload"); }
public OperationCompletedEventArgs( object data, Exception ex, bool cancelled, object userState) : base(ex, cancelled, userState) { _data = data as Submission; }
protected void insertSubmission(Submission submission) { if (submission != null) { submission.LastStatusUpdate = DateTime.Now; //store submission to database _workUnit.SubmissionRepository.InsertEntity(submission); _workUnit.SaveChanges();//update submission status } }
protected void updateSubmission(Submission submission) { if (submission != null) { submission.LastStatusUpdate = DateTime.Now; _workUnit.SubmissionRepository.UpdateEntity(submission); _workUnit.SaveChanges(); } }
public ActionResult MapData(DataMappingModel mappingModel, Submission submission) { if (Session[uploadKey] == null) { updateStatusMessage("Your session has expired. Please upload a new file."); return RedirectToAction("Index", "Home"); } //get mappnig columns var columns = mappingModel.MappingObject; var defaultData = mappingModel.DefaultData; //get upload data var obj = Session[uploadKey] as dynamic; var data = obj.data as IEnumerable<IDictionary<string, object>>; //data to be stored IList<ServiceCensusBlock> dataList = new List<ServiceCensusBlock>(); IDictionary<int, object> errorList = new Dictionary<int, object>(); //by pass DefaultData validation var defaultDataModelStates = ModelState.Where(x => x.Key.Contains("DefaultData")).ToList(); foreach (var state in defaultDataModelStates) { ModelState.Remove(state.Key);//remove these DefaultData states } //now that the model is valid we can start mapping data if (ModelState.IsValid) { int count = 1;//start at line 1 foreach (var entry in data) { short tempShort; object tempValue; string str, key, useDefault = "Use default"; try { ModelState.Clear();//clear model state to validate transfer data #region data transfer var dataEntry = new ServiceCensusBlock(); //PROVIDER NAME key = columns.PROVNAMEColumn; tempValue = key == useDefault ? defaultData.PROVNAME : entry[key]; dataEntry.PROVNAME = tempValue != null ? tempValue.ToString() : string.Empty; key = columns.DBANAMEColumn; tempValue = key == useDefault ? defaultData.DBANAME : entry[key]; dataEntry.DBANAME = tempValue != null ? tempValue.ToString() : dataEntry.DBANAME; key = columns.Provider_typeColumn; tempValue = key == useDefault ? defaultData.Provider_Type : entry[key]; str = tempValue != null ? tempValue.ToString() : ""; dataEntry.Provider_Type = short.TryParse(str, out tempShort) ? tempShort : (short)-9999; key = columns.FRNColumn; tempValue = key == useDefault ? defaultData.FRN : entry[key]; dataEntry.FRN = tempValue != null ? tempValue.ToString().Replace("-", "") : dataEntry.FRN; key = columns.FULLFIPSIDColumn; tempValue = key == useDefault ? defaultData.FULLFIPSID : entry[key]; dataEntry.FULLFIPSID = tempValue != null ? tempValue.ToString() : dataEntry.FULLFIPSID; key = columns.TRANSTECHColumn; tempValue = key == useDefault ? defaultData.TRANSTECH : entry[key]; str = tempValue != null ? tempValue.ToString() : ""; dataEntry.TRANSTECH = short.TryParse(str, out tempShort) ? tempShort : dataEntry.TRANSTECH; key = columns.MAXADDOWNColumn; tempValue = key == useDefault ? defaultData.MAXADDOWN : entry[key]; dataEntry.MAXADDOWN = tempValue != null ? tempValue.ToString() : dataEntry.MAXADDOWN; key = columns.MAXADUPColumn; tempValue = key == useDefault ? defaultData.MAXADUP : entry[key]; dataEntry.MAXADUP = tempValue != null ? tempValue.ToString() : dataEntry.MAXADUP; try { key = columns.TYPICDOWNColumn; tempValue = key == useDefault ? defaultData.TYPICDOWN : entry[key]; dataEntry.TYPICDOWN = tempValue != null ? tempValue.ToString() : dataEntry.TYPICDOWN; } catch { //reserve default value if error occurs } try { key = columns.TYPICUPColumn; tempValue = key == useDefault ? defaultData.TYPICUP : entry[key]; dataEntry.TYPICUP = tempValue != null ? tempValue.ToString() : dataEntry.TYPICUP; } catch { //reserve default value if error occurs } #endregion //validate data for each entry TryValidateModel(dataEntry); if (ModelState.IsValid) { dataList.Add(dataEntry); } else { //redirect to report errors errorList.Add(count, ModelState.ToList()); } } catch (Exception ex) { ViewBag.errorMsg = "Error processing submitted data. " + ex.Message; return View("Error"); } count++;//increase count } //Session[uploadKey] = null;//discard session data //store data to be committed to session Session[mappingKey] = new { mappingObject = columns, validData = dataList, defaultData = defaultData }; //get submission if (submission != null) { submission.DataCount = dataList.Count; submission.RecordsStored = 0; submission.ProgressPercentage = 0; //check if the entry is already in the database if (submission.SubmissionID == 0) insertSubmission(submission); } //prepare view model var previewData = new PreviewMappingModel(); previewData.SuccessCount = dataList.Count(); previewData.ErrorList = errorList; previewData.Data = dataList; previewData.SubmissionID = submission.SubmissionID; return View("ReviewMapping", previewData); } //error has occured else { //re-populate view data List<string> uploadedColumns = data.First().Keys.ToList(); //add 'use default' value to apply default values uploadedColumns.Add("Use default"); mappingModel.UploadDataColumns = uploadedColumns; //data first row ViewBag.firstRowData = data.First().ToJSon(); return View(mappingModel); } }