protected void btnUpload_Click(object sender, EventArgs e) { if (RadAsyncUploadMenu.UploadedFiles.Count == 0) { return; } UploadedFile attachment = RadAsyncUploadMenu.UploadedFiles[0]; int userId = Convert.ToInt32(Session["USERID"]); var classId = Convert.ToInt32(ddlClass.SelectedValue); var menuTypeId = 1; //TODO: build this for all menu types for the class, call the ImportMenu in loop for all menu types var menuTypes = _menuManagement.GetMenuTypeByClass(classId); foreach (var menuType in menuTypes) { _menuProcessor.ImportMenu(Convert.ToInt64(ddlCycle.SelectedValue), Convert.ToInt32(ddlClass.SelectedValue), menuType.ID, attachment.InputStream, userId); } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "UploadCompleted", "UploadCompleted();", true); //if (classId == 1) // menuTypeId = 1; //else if (classId == 2) // menuTypeId = 10; //else // menuTypeId = 13; //_menuProcessor.ImportMenu(Convert.ToInt64(ddlCycle.SelectedValue), Convert.ToInt32(ddlClass.SelectedValue), menuTypeId, attachment.InputStream, userId); }
/// <summary> /// Uplaod service plan /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpload_Click(object sender, EventArgs e) { try { if (RadAsyncUploadMenu.UploadedFiles.Count == 0) { return; } int userId = Convert.ToInt32(Session["USERID"]); var user = _accountManagement.GetUserById(userId); var servicePlanNames = ""; bool validInput = InvalidUploadInput(); if (!validInput) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "InValidUploadFile", "InValidUploadFile();", true); return; } string notificationEmails = (System.Configuration.ConfigurationManager.AppSettings["NotificationEmails"]); var emails = notificationEmails.Split(new char[] { ';' }); for (int i = 0; i < RadAsyncUploadMenu.UploadedFiles.Count; i++) { UploadedFile attachment = RadAsyncUploadMenu.UploadedFiles[i]; servicePlanNames += attachment.FileName + ","; //validate before upload var missingServiceCode = _menuProcessor.ValidateServicePlanMenu(attachment.InputStream); if (missingServiceCode.Count > 0) { //Loop with comma separated value var missingCode = string.Empty; for (int j = 0; j < missingServiceCode.Count; j++) { missingCode += missingServiceCode[j] + ","; } //send email var defaultMessage = EmailHelper.MissingBaseItemEmailTemplate; defaultMessage = EmailHelper.ConvertMail2(defaultMessage, missingCode, "\\[BASEITEMS\\]"); EmailHelper.SendMail(user.Username, "*****@*****.**", "EMMA- Service Plan Validation - " + attachment.FileName, defaultMessage); foreach (var email in emails) { if (!string.IsNullOrEmpty(email)) { EmailHelper.SendMail(email, "*****@*****.**", "EMMA- Service Plan Validation - " + attachment.FileName, defaultMessage); } } if (RadAsyncUploadMenu.UploadedFiles.Count == 1) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "NotValid", "NotValid();", true); return; } continue; } var classId = Convert.ToInt32(ddlClass.SelectedValue); var menuTypeId = 1; //TODO: build this for all menu types for the class, call the ImportMenu in loop for all menu types var menuTypes = _menuManagement.GetMenuTypeByClass(classId); foreach (var menuType in menuTypes) { //TODO: uncomment below while testing //if (menuType.ID == 1) _menuProcessor.ImportMenu(Convert.ToInt64(ddlCycle.SelectedValue), Convert.ToInt32(ddlClass.SelectedValue), menuType.ID, attachment.InputStream, userId); } //send email var uploadMessage = EmailHelper.UploadCompleteEmailTemplate; uploadMessage = EmailHelper.ConvertMail2(uploadMessage, attachment.FileName, "\\[SERVICEPLANNAME\\]"); EmailHelper.SendMail(user.Username, "*****@*****.**", "EMMA- Service Plan Upload", uploadMessage); foreach (var email in emails) { if (!string.IsNullOrEmpty(email)) { EmailHelper.SendMail(email, "*****@*****.**", "EMMA- Service Plan Validation", uploadMessage); } } } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "UploadCompleted", "UploadCompleted();", true); } catch (Exception ex) { //write to Elma ErrorSignal.FromCurrentContext().Raise(ex); } }