// Create or Update public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata) { string data = string.Empty; string bvin = FirstParameter(parameters); ApiResponse<ProductFileDTO> response = new ApiResponse<ProductFileDTO>(); ProductFileDTO postedItem = null; try { postedItem = MerchantTribe.Web.Json.ObjectFromJson<ProductFileDTO>(postdata); } catch(Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return MerchantTribe.Web.Json.ObjectToJson(response); } ProductFile item = new ProductFile(); item.FromDto(postedItem); if (bvin == string.Empty) { if (MTApp.CatalogServices.ProductFiles.Create(item)) { bvin = item.Bvin; } } else { MTApp.CatalogServices.ProductFiles.Update(item); } ProductFile resultItem = MTApp.CatalogServices.ProductFiles.Find(bvin); if (resultItem != null) response.Content = resultItem.ToDto(); data = MerchantTribe.Web.Json.ObjectToJson(response); return data; }
protected void ImportLinkButton_Click(object sender, System.EventArgs e) { string[] files = System.IO.Directory.GetFiles(Server.MapPath(Request.ApplicationPath) + "\\Files\\"); bool errorOccurred = false; foreach (string fileName in files) { if (!fileName.ToLower().EndsWith(".config")) { ProductFile file = new ProductFile(); file.FileName = System.IO.Path.GetFileName(fileName); file.ShortDescription = file.FileName; if (MTApp.CatalogServices.ProductFiles.Create(file)) { try { System.IO.FileStream fileStream = new System.IO.FileStream(fileName, FileMode.Open); try { if (ProductFile.SaveFile(MTApp.CurrentStore.Id, file.Bvin, file.FileName, fileStream)) { fileStream.Close(); try { File.Delete(fileName); } catch (Exception ex) { errorOccurred = true; EventLog.LogEvent(ex); } } } finally { try { fileStream.Close(); } catch { } } } catch (Exception ex) { errorOccurred = true; EventLog.LogEvent(ex); } } } } if (errorOccurred) { MessageBox1.ShowError("An error occurred during import. Please check the event log."); } else { MessageBox1.ShowOk("Files Imported Successfully."); } BindFileGridView(); }
public static System.IO.FileStream GetPhysicalFile(ProductFile f, string path) { string diskFileName = f.Bvin + "_" + f.FileName + ".config"; return Storage.DiskStorage.FileVaultGetStream(f.StoreId, diskFileName); }
private bool Save(ProductFile f) { if (f.Bvin == string.Empty) { return MyPage.MTApp.CatalogServices.ProductFiles.Create(f); } else { return MyPage.MTApp.CatalogServices.ProductFiles.Update(f); } }
public void DownloadOrLinkFile(ProductFile file, IMessageBox MessageBox1) { //if they browsed a file then this overrides all other behavior if (_currentMode == Mode.NewUpload) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { if (ProductFile.SaveFile(MyPage.MTApp.CurrentStore.Id, file.Bvin, file.FileName, NewFileUpload.PostedFile)) { MessageBox1.ShowOk("File saved to server successfully"); } else { MessageBox1.ShowError("There was an error while trying to save your file to the file system. Please check your asp.net permissions."); } } else { MessageBox1.ShowError("There was an error while trying to save your file to the database."); } } else if (_currentMode == Mode.DropDownList) { if (FilesDropDownList.SelectedValue.Trim() != "") { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { MessageBox1.ShowOk("File saved to server successfully"); } else { MessageBox1.ShowError("There was an error while trying to save your file to the database."); } } } else if (_currentMode == Mode.FileBrowsed) { if (file == null) { file = new ProductFile(); } InitializeProductFile(file, true); if (Save(file)) { MessageBox1.ShowOk("File saved to server successfully"); } else { MessageBox1.ShowError("There was an error while trying to save your file to the database."); } } InitializeFileLists(); }
protected void InitializeProductFile(ProductFile file, bool updateFileName) { if (updateFileName) { ProductFile otherFile = null; if (_currentMode == Mode.DropDownList) { otherFile = MyPage.MTApp.CatalogServices.ProductFiles.Find(FilesDropDownList.SelectedValue); file.Bvin = otherFile.Bvin; file.FileName = otherFile.FileName; } else if (_currentMode == Mode.FileBrowsed) { otherFile = MyPage.MTApp.CatalogServices.ProductFiles.Find(FileIdHiddenField.Value); file.Bvin = otherFile.Bvin; file.FileName = otherFile.FileName; } else if (_currentMode == Mode.NewUpload) { file.FileName = System.IO.Path.GetFileName(NewFileUpload.FileName); } } else { if (_currentMode == Mode.NewUpload) { file.FileName = System.IO.Path.GetFileName(NewFileUpload.FileName); } } if (this.DisplayShortDescription) { file.ShortDescription = ShortDescriptionTextBox.Text.Trim(); } if (this.ProductId != string.Empty) { file.ProductId = this.ProductId; file.SetMinutes(AvailableForTimespanPicker.Months, AvailableForTimespanPicker.Days, AvailableForTimespanPicker.Hours, AvailableForTimespanPicker.Minutes); if (NumberOfDownloadsTextBox.Text.Trim() != string.Empty) { file.MaxDownloads = int.Parse(NumberOfDownloadsTextBox.Text); } else { file.MaxDownloads = 0; } } }
protected void DescriptionIsUniqueToProductCustomValidator_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args) { args.IsValid = true; ProductFile file = null; if (_currentMode == Mode.DropDownList) { } //file = Catalog.ProductFile.FindByBvin(FilesDropDownList.SelectedValue) else if (_currentMode == Mode.FileBrowsed) { } //file = Catalog.ProductFile.FindByBvin(FileIdHiddenField.Value) else if (_currentMode == Mode.NewUpload) { file = new ProductFile(); } if (file != null) { InitializeProductFile(file, false); List<ProductFile> result = MyPage.MTApp.CatalogServices.ProductFiles.FindByFileNameAndDescription(file.FileName, ShortDescriptionTextBox.Text); if (result.Count > 0) { args.IsValid = false; } } }