Beispiel #1
0
    //-----------------------------------------------
    #endregion

    #region ---------------btnSave_Click---------------
    //-----------------------------------------------
    //btnSave_Click
    //-----------------------------------------------
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid || (currentModule.HasItemDate && !ucItemDate.IsValid) || (currentModule.HasItemEndDate && !ucItemEndDate.IsValid))
        {
            return;
        }
        //--------------------------------------------------
        ItemsEntity itemsObject = new ItemsEntity();

        //--------------------------------------------------
        #region Item Files properties

        // uploaded files extenssions
        string uploadedPhotoExtension  = Path.GetExtension(fuPhoto.FileName);
        string uploadedFileExtension   = Path.GetExtension(fuFile.FileName);
        string uploadedVideoExtension  = Path.GetExtension(fuVideo.FileName);
        string uploadedAudioExtension  = Path.GetExtension(fuAudio.FileName);
        string uploadedPhoto2Extension = Path.GetExtension(fuPhoto2.FileName);
        //---------------------------------------------------------------------
        #region Uploaded Files checks
        #region Uploaded photo file checks
        if (fuPhoto.HasFile)
        {
            if (!MoversFW.Photos.CheckIsImage(fuPhoto.PostedFile))
            {
                lblResult.CssClass = "lblResult_Faild";
                lblResult.Text     = Resources.AdminText.InvalidPhotoFile;
                return;
            }

            /*
             * //Check suported extention
             * if (!SiteSettings.CheckUploadedFileExtension(uploadedPhotoExtension, currentModule.PhotoAvailableExtension))
             * {
             *  lblResult.CssClass = "lblResult_Faild";
             *  lblResult.Text = Resources.AdminText.NotSuportedFileExtention + currentModule.PhotoAvailableExtension;
             *  return;
             * }*/
            //Check max length
            if (!SiteSettings.CheckUploadedFileLength(fuPhoto.PostedFile.ContentLength, currentModule.PhotoMaxSize))
            {
                lblResult.CssClass = "lblResult_Faild";
                lblResult.Text     = Resources.AdminText.UploadedFileGreaterThanMaxLength + currentModule.PhotoMaxSize;
                return;
            }
            //--------------------------------------------------------------------
        }
        #endregion
        #region Uploaded file checks
        //File
        if (fuFile.HasFile)
        {/*
          * //Check suported extention
          * if (!SiteSettings.CheckUploadedFileExtension(uploadedFileExtension, currentModule.FileAvailableExtension))
          * {
          *     lblResult.CssClass = "lblResult_Faild";
          *     lblResult.Text = Resources.AdminText.NotSuportedFileExtention + currentModule.FileAvailableExtension;
          *     return;
          * }*/
            //Check max length
            if (!SiteSettings.CheckUploadedFileLength(fuFile.PostedFile.ContentLength, currentModule.FileMaxSize))
            {
                lblResult.CssClass = "lblResult_Faild";
                lblResult.Text     = Resources.AdminText.UploadedFileGreaterThanMaxLength + currentModule.FileMaxSize;
                return;
            }
        }
        //-----------------------------------------------------------------
        #endregion
        #region Uploaded video file checks
        //Video
        if (fuVideo.HasFile)
        {/*
          * //Check suported extention
          * if (!SiteSettings.CheckUploadedFileExtension(uploadedVideoExtension, currentModule.VideoAvailableExtension))
          * {
          *     lblResult.CssClass = "lblResult_Faild";
          *     lblResult.Text = Resources.AdminText.NotSuportedVideoExtention + currentModule.VideoAvailableExtension;
          *     return;
          * }*/
            //Check max length
            if (!SiteSettings.CheckUploadedFileLength(fuVideo.PostedFile.ContentLength, currentModule.VideoMaxSize))
            {
                lblResult.CssClass = "lblResult_Faild";
                lblResult.Text     = Resources.AdminText.UploadedVideoGreaterThanMaxLength + currentModule.VideoMaxSize;
                return;
            }
        }
        //-----------------------------------------------------------------
        #endregion
        #region Uploaded audio file checks
        //Audio
        if (fuAudio.HasFile)
        {/*
          * //Check suported extention
          * if (!SiteSettings.CheckUploadedFileExtension(uploadedAudioExtension, currentModule.AudioAvailableExtension))
          * {
          *     lblResult.CssClass = "lblResult_Faild";
          *     lblResult.Text = Resources.AdminText.NotSuportedAudioExtention + currentModule.VideoAvailableExtension;
          *     return;
          * }*/
            //Check max length
            if (!SiteSettings.CheckUploadedFileLength(fuAudio.PostedFile.ContentLength, currentModule.AudioMaxSize))
            {
                lblResult.CssClass = "lblResult_Faild";
                lblResult.Text     = Resources.AdminText.UploadedAudioGreaterThanMaxLength + currentModule.AudioMaxSize;
                return;
            }
        }
        //-----------------------------------------------------------------
        #endregion
        #region Uploaded photo2 file checks
        //-----------------------------------------------------------------
        //Photo2
        if (fuPhoto2.HasFile)
        {
            if (!MoversFW.Photos.CheckIsImage(fuPhoto2.PostedFile))
            {
                lblResult.CssClass = "lblResult_Faild";
                lblResult.Text     = Resources.AdminText.InvalidPhotoFile;
                return;
            }/*
              * //Check suported extention
              * if (!SiteSettings.CheckUploadedFileExtension(uploadedPhoto2Extension, currentModule.Photo2AvailableExtension))
              * {
              * lblResult.CssClass = "lblResult_Faild";
              * lblResult.Text = Resources.AdminText.NotSuportedFileExtention + currentModule.Photo2AvailableExtension;
              * return;
              * }*/
            //Check max length
            if (!SiteSettings.CheckUploadedFileLength(fuPhoto2.PostedFile.ContentLength, currentModule.Photo2MaxSize))
            {
                lblResult.CssClass = "lblResult_Faild";
                lblResult.Text     = Resources.AdminText.UploadedFileGreaterThanMaxLength + currentModule.Photo2MaxSize;
                return;
            }
            //--------------------------------------------------------------------
        }
        //-----------------------------------------------------------------
        #endregion
        #endregion



        #region Set properties
        //items files
        itemsObject.PhotoExtension  = uploadedPhotoExtension;
        itemsObject.FileExtension   = uploadedFileExtension;
        itemsObject.VideoExtension  = uploadedVideoExtension;
        itemsObject.AudioExtension  = uploadedAudioExtension;
        itemsObject.Photo2Extension = uploadedPhoto2Extension;
        //------------------------------------------------------
        #endregion
        #endregion

        //itemsObject.Title = txtTitle.Text;
        if (trCategoryID.Visible)
        {
            itemsObject.CategoryID = Convert.ToInt32(ddlItemCategories.SelectedValue);
        }
        //itemsObject.ShortDescription = txtShortDescription.Text;
        //itemsObject.Description = txtDetails.Value;
        itemsObject.Email = txtEmail.Text;

        // itemsObject.AuthorName = txtAuthorName.Text;
        if (currentModule.HasPriority && Sender == UsersTypes.Admin)
        {
            itemsObject.Priority = Convert.ToInt32(ddlPriority.SelectedValue);
        }
        itemsObject.Url = txtUrl.Text;
        if (currentModule.HasHeight)
        {
            itemsObject.Height = Convert.ToInt32(txtHeight.Text);
        }
        if (currentModule.HasWidth)
        {
            itemsObject.Width = Convert.ToInt32(txtWidth.Text);
        }
        //if (currentModule.HasItemDate && !string.IsNullOrEmpty(txtItemDate.Text)) itemsObject.ItemDate = Convert.ToDateTime(txtItemDate.Text);
        if (currentModule.HasItemDate && ucItemDate.Date != DateTime.MinValue)
        {
            itemsObject.ItemDate = ucItemDate.Date;
        }
        //-----------------------------------
        //ItemEndDate
        //if (currentModule.HasItemEndDate && !string.IsNullOrEmpty(txtItemEndDate.Text)) itemsObject.ItemEndDate = Convert.ToDateTime(txtItemEndDate.Text);
        if (currentModule.HasItemEndDate && ucItemEndDate.Date != DateTime.MinValue)
        {
            itemsObject.ItemEndDate = ucItemEndDate.Date;
        }

        //itemsObject.Address = txtAddress.Text;
        itemsObject.MailBox = txtMailBox.Text;
        itemsObject.ZipCode = txtZipCode.Text;
        itemsObject.Tels    = txtTels.Text;
        itemsObject.Fax     = txtFax.Text;
        itemsObject.Mobile  = txtMobile.Text;
        //-------------------------------------------------------------------------------------------
        itemsObject.IsMain        = CbIsMain.Checked;
        itemsObject.SpecialOption = cbSpecialOption.Checked;
        itemsObject.ModuleTypeID  = ModuleTypeID;
        //-----------------------------------
        itemsObject.YoutubeCode = txtYoutubeCode.Text;
        //---------------------------------------------------------------------------------------------------------
        if (currentModule.HasGoogleLatitude)
        {
            itemsObject.GoogleLatitude = Convert.ToDouble(txtGoogleLatitude.Text);
        }
        //---------------------------------------------------------------------------------------------------------
        if (currentModule.HasGoogleLongitude)
        {
            itemsObject.GoogleLongitude = Convert.ToDouble(txtGoogleLongitude.Text);
        }
        //---------------------------------------------------------------------------------------------------------
        itemsObject.Price            = txtPrice.Text;
        itemsObject.OnlyForRegisered = cbOnlyForRegisered.Checked;
        //---------------------------------------------------------------------------------------------------------
        //Files publishing
        itemsObject.PublishPhoto  = cbPublishPhoto.Checked;
        itemsObject.PublishPhoto2 = cbPublishPhoto2.Checked;
        itemsObject.PublishFile   = cbPublishFile.Checked;
        itemsObject.PublishAudio  = cbPublishAudio.Checked;
        itemsObject.PublishVideo  = cbPublishVideo.Checked;
        itemsObject.PublishYoutbe = cbPublishYoutbe.Checked;
        //---------------------------------------------------------------------------------------------------------
        if (currentModule.HasAuthorID)
        {
            int authorID = Convert.ToInt32(ddlAuthorID.SelectedValue);
            itemsObject.AuthorID = authorID;
            if (authorID > 0)
            {
                itemsObject.AuthorName = ddlAuthorID.SelectedItem.Text;
                selectedAuthor         = ItemsFactory.GetObject(authorID, Languages.Unknowen, UsersTypes.Admin, OwnerID);
            }
        }
        //-------------------------------------------------------------------------------------------
        //Check is  available
        // logic of is available "if the module hasn't IsAvailable -> then  All items ara vailable "
        if (currentModule.HasIsAvailable && Sender == UsersTypes.Admin)
        {
            itemsObject.IsAvailable = cbIsAvailable.Checked;
        }
        else if (Sender == UsersTypes.User)
        {
            itemsObject.IsAvailable = false;
        }
        else
        {
            itemsObject.IsAvailable = true;
        }
        //-------------------------------------------------------------------------------------------
        itemsObject.Icon = txtIconControl.Text;

        //-----------------------------------------------
        //Visitors Participations
        //----------------------------
        if (Sender == UsersTypes.User || Sender == UsersTypes.SuperUser)
        {
            //----------------------------------------------------------------------------------------
            if (this.Page.User != null && this.Page.User.Identity.IsAuthenticated && !UsersDataFactory.IsCurrentUserTheAdmin())
            {
                MembershipUser user   = Membership.GetUser(this.Page.User.Identity.Name);
                Guid           userID = new Guid(user.ProviderUserKey.ToString());
                itemsObject.UserId = userID;
                UsersDataEntity userData = UsersDataFactory.GetUsersDataObject(userID, OwnerID);
                itemsObject.SenderName  = userData.Name;
                itemsObject.SenderEMail = user.Email;
            }
            else
            {
                itemsObject.SenderName  = txtSenderName.Text;
                itemsObject.SenderEMail = txtSenderEMail.Text;
            }
            //----------------------------------------------------------------------------------------
            //HasSenderCountryID
            if (currentModule.HasSenderCountryID)
            {
                itemsObject.SenderCountryID = Convert.ToInt32(ddlSenderCountry.SelectedValue);
            }
            //----------------------------------------------------------------------------------------
            itemsObject.IsVisitorsParticipations = true;
        }
        //----------------------------------------------------------------------------------------
        if (OwnerID != null)
        {
            itemsObject.OwnerID = (Guid)OwnerID;
        }
        //-------------------------------------------------------------------------------------------
        if (currentModule.HasType)
        {
            itemsObject.Type = Convert.ToInt32(ddlType.SelectedValue);
        }
        //-------------------------------------------------------------------------------------------

        //Details -----------------------
        AddDetails(itemsObject);
        //----------------------------------------------------------------------------------------
        if (itemsObject.Details.Count == 0)
        {
            if (SiteSettings.Languages_HasArabicLanguages)
            {
                ItemsDetailsEntity arabicDetails = new ItemsDetailsEntity();
                arabicDetails.LangID = Languages.Ar;
                itemsObject.Details[Languages.Ar] = arabicDetails;
            }
            if (SiteSettings.Languages_HasEnglishLanguages)
            {
                ItemsDetailsEntity englishDetails = new ItemsDetailsEntity();
                englishDetails.LangID             = Languages.En;
                itemsObject.Details[Languages.En] = englishDetails;
            }
        }
        //----------------------------------------------------------------------------------------

        //ItemsDetailsEntity d = itemsObject.Details[Languages.Ar];
        //if(selectedAuthor!=n)
        //-------------------------------
        ExecuteCommandStatus status = ItemsFactory.Create(itemsObject, currentModule);
        if (status == ExecuteCommandStatus.Done)
        {
            SaveFiles(itemsObject);
            //------------------------------------------------------------------------
            //RegisterInMailList
            if (currentModule.MailListAutomaticRegistration && !string.IsNullOrEmpty(itemsObject.Email))
            {
                ItemsFactory.RegisterInMailList(itemsObject);
            }
            //------------------------------------------------------------------------
            //RegisterInSms
            if (currentModule.SmsAutomaticRegistration && !string.IsNullOrEmpty(itemsObject.Mobile))
            {
                ItemsFactory.RegisterInSms(itemsObject);
            }
            //------------------------------------------------------------------------
            lblResult.CssClass = "lblResult_Done";
            lblResult.Text     = Resources.AdminText.AddingOperationDone;
            ClearControls();
        }
        else if (status == ExecuteCommandStatus.AllreadyExists)
        {
            lblResult.CssClass = "lblResult_Faild";
            lblResult.Text     = Resources.AdminText.DuplicateItem;
        }
        else
        {
            lblResult.CssClass = "lblResult_Faild";
            lblResult.Text     = Resources.AdminText.AddingOperationFaild;
        }
    }