コード例 #1
0
        protected void UploadImageClick(object sender, EventArgs e)
        {
            if (SubscriptionImage.HasFile)
            {
                var file = SubscriptionImage.PostedFile;
                if (Request.Params["id"] != "0")
                {
                    string pathString     = Server.MapPath(string.Format("/HotelImage/s{0}/", _subscriptions.Id));
                    string localImageFile = string.Format("/HotelImage/s{0}/{1}", _subscriptions.Id, file.FileName);

                    if (!Directory.Exists(pathString))
                    {
                        Directory.CreateDirectory(pathString);
                    }
                    try
                    {
                        file.SaveAs(Server.MapPath(localImageFile));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }

                    var image = new SubscriptionImages
                    {
                        SubscriptionId = _subscriptions.Id,
                        Url            = localImageFile,
                        IsActive       = true,
                        Order          = IsCoverCheckbox.Checked ? 1 : 2,
                        IsCover        = IsCoverCheckbox.Checked
                    };

                    _subscriptionRepository.AddImage(image);

                    _subscriptionRepository.ResetCache();

                    Response.Redirect(Request.Url.AbsoluteUri, true);
                }
            }
        }