public async Task <bool> AttachmentToComment(CommentAttachmentViewModel commentAttachment)
        {
            var comment = await _publicContext.Comment.FirstOrDefaultAsync(x => x.Id == commentAttachment.CommentId);

            if (comment == null)
            {
                ExceptionFactory.SoftException(ExceptionEnum.CommentNotFound, "Comment not found");
            }

            if (!await _publicContext.Attachment.AnyAsync(x => x.Id == commentAttachment.AttachmentId))
            {
                ExceptionFactory.SoftException(ExceptionEnum.AttachmentNotFound,
                                               $"Attachment {commentAttachment.AttachmentId} not found");
            }

            var attachmentToComment = new AttachmentComment()
            {
                AttachmentId = commentAttachment.AttachmentId,
                CommentId    = commentAttachment.CommentId,
            };

            await _publicContext.AttachmentComment.AddAsync(attachmentToComment);

            await _publicContext.SaveChangesAsync();

            return(true);
        }
예제 #2
0
        private async Task AttachFileToComment(int commentId, int attachmentId)
        {
            if (await _context.Attachment.AnyAsync(x => x.Id == attachmentId))
            {
                var attachmentComment = new AttachmentComment()
                {
                    AttachmentId = attachmentId,
                    CommentId    = commentId
                };

                await _context.AttachmentComment.AddAsync(attachmentComment);
            }
        }
예제 #3
0
        protected void bAjaxPostback_Click(object sender, EventArgs e)
        {
            try
            {
                aqufitEntities entities = new aqufitEntities();
                Affine.Data.Managers.IDataManager dataMan = Affine.Data.Managers.LINQ.DataManager.Instance;
                long pId = -1;
                switch (hiddenAjaxAction.Value)
                {
                case "loadPhoto":
                    pId = Convert.ToInt64(hiddenAjaxValue.Value);
                    string url = SetupPhoto(pId);
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.Actions.LoadImage('" + url + "', " + lPhotoNum.Text + ");");
                    break;

                case "makeProfile":
                    pId = Convert.ToInt64(hiddenAjaxValue.Value);
                    Affine.Utils.ImageUtil.MakeProfileFromPhoto(UserSettings.Id, pId, Server.MapPath("~"));
                    string profileUrl = ResolveUrl("~") + UserSettings.UserName;
                    RadAjaxManager1.ResponseScripts.Add("top.location.href='" + profileUrl + "'; Aqufit.Page.atiLoading.remove();");
                    break;

                case "tagPhoto":
                    Affine.Data.Helpers.PhotoTag json = JsonExtensionsWeb.FromJson <Affine.Data.Helpers.PhotoTag>(hiddenAjaxValue.Value);
                    pId = Convert.ToInt64(hiddenPhotoId.Value);
                    // TODO: security
                    dataMan.TagPhoto(UserSettings.Id, json.FriendId, pId, json.Top, json.Left, json.Width, json.Height);
                    RadAjaxManager1.ResponseScripts.Add("radalert('<div style=\"width: 100%; height: 100%; padding: 0px;\"><span style=\"color: #FFF;\"><img src=\"" + ResolveUrl("~/DesktopModules/ATI_Base/resources/images/iCheck.png") + "\" align=\"absmiddle\"/> Photo has been tagged</span></div>', 330, 100, 'Success');");
                    break;

                case "addComment":
                    pId = Convert.ToInt64(hiddenPhotoId.Value);
                    string            comment = hiddenAjaxValue.Value;
                    AttachmentComment pc      = dataMan.SavePhotoComment(UserSettings.Id, pId, comment);
                    string            j       = new { UserName = pc.UserSetting.UserName, UserKey = pc.UserSetting.UserKey, Comment = pc.Comment }.ToJson();
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.Actions.appendComment('" + j + "'); ");
                    break;

                case "deletePhoto":
                    pId = Convert.ToInt64(hiddenPhotoId.Value);
                    dataMan.DeletePhoto(UserSettings.Id, pId);
                    Response.Redirect(ResolveUrl("~") + UserSettings.UserName + "/photos", true);
                    //RadAjaxManager1.ResponseScripts.Add("alert('"+pId+"');");
                    break;

                case "deleteAlbum":
                    long aId = Convert.ToInt64(hiddenAlbumKey.Value);
                    dataMan.DeleteAlbum(UserSettings.Id, aId);
                    Response.Redirect(ResolveUrl("~") + UserSettings.UserName + "/photos", true);
                    //RadAjaxManager1.ResponseScripts.Add("alert('"+pId+"');");
                    break;

                case "deleteTag":
                    long       tId = Convert.ToInt64(hiddenAjaxValue.Value);
                    User2Photo u2p = entities.User2Photo.FirstOrDefault(p => p.Id == tId && (p.UserSettingsKey == UserSettings.Id || p.TaggerUserSettingsKey == UserSettings.Id));
                    if (u2p != null)
                    {
                        entities.DeleteObject(u2p);
                        entities.SaveChanges();
                        RadAjaxManager1.ResponseScripts.Add("radalert('<div style=\"width: 100%; height: 100%; padding: 0px;\"><span style=\"color: #FFF;\"><img src=\"" + ResolveUrl("~/DesktopModules/ATI_Base/resources/images/iCheck.png") + "\" align=\"absmiddle\"/> Tag has been removed</span></div>', 330, 100, 'Success');");
                    }
                    RadAjaxManager1.ResponseScripts.Add("Aqufit.Page.atiLoading.remove(); ");
                    break;
                }
            }
            catch (Exception ex)
            {
                // TODO: better error handling
                RadAjaxManager1.ResponseScripts.Add(" alert('" + ex.Message + "'); ");
            }
        }