private void CreateAction() { if (!IsValidData()) { return; } var productId = ProductService.GetProductId(txtProductArtNo.Text); try { var action = new BuyInTimeProductModel() { ProductId = productId, DiscountInTime = txtDiscount.Text.TryParseFloat(), DateStart = txtDateStart.Text.TryParseDateTime(), DateExpired = txtDateExpired.Text.TryParseDateTime(), ShowMode = ddlShowMode.SelectedValue.TryParseInt(), ActionText = ckeActionText.Text, IsRepeat = chkIsRepeat.Checked, DaysRepeat = txtDaysRepeat.Text.TryParseInt(1), SortOrder = txtSortOrder.Text.TryParseInt(0) }; BuyInTimeService.Add(action); txtProductArtNo.Text = txtDiscount.Text = txtDateExpired.Text = txtDateStart.Text = string.Empty; if (fuPucture.HasFile) { if (!FileHelpers.CheckFileExtension(fuPucture.FileName, FileHelpers.eAdvantShopFileTypes.Image)) { MsgErr("Неправильный формат"); return; } var fileName = action.Id + Path.GetExtension(fuPucture.FileName); if (!Directory.Exists(BuyInTimeService.PicturePath)) { Directory.CreateDirectory(BuyInTimeService.PicturePath); } fuPucture.SaveAs(BuyInTimeService.PicturePath + fileName); BuyInTimeService.UpdatePicture(action.Id, fileName); } } catch (Exception ex) { MsgErr("cant add" + ex); } txtProductArtNo.Text = string.Empty; }
protected void DeletePicture_Click(object sender, EventArgs e) { if (_action == null) { _action = BuyInTimeService.Get(Id); } var filepath = BuyInTimeService.PicturePath + _action.Picture; if (File.Exists(filepath)) { File.Delete(filepath); BuyInTimeService.UpdatePicture(_action.Id, null); pnlPicture.Visible = false; fuPucture.Visible = true; } }