Ejemplo n.º 1
0
        public async Task <IActionResult> GetPublishingQueueStatus([FromQuery] PagingParameterModel paging, bool unfinished)
        {
            Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
            Guid sessionId      = new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value);
            RServiceResult <bool>
            canViewAll =
                await _userPermissionChecker.Check
                (
                    loggedOnUserId,
                    sessionId,
                    RMuseumSecurableItem.AudioRecitationEntityShortName,
                    RMuseumSecurableItem.ModerateOperationShortName
                );

            if (!string.IsNullOrEmpty(canViewAll.ExceptionString))
            {
                return(BadRequest(canViewAll.ExceptionString));
            }

            var res = await _audioService.GetPublishingQueueStatus(paging, unfinished, canViewAll.Result?Guid.Empty : loggedOnUserId);

            if (!string.IsNullOrEmpty(res.ExceptionString))
            {
                return(BadRequest(res.ExceptionString));
            }
            // Paging Header
            HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(res.Result.PagingMeta));

            return(Ok(res.Result.Items));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteMyComment(int id)
        {
            Guid userId =
                new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
            Guid sessionId =
                new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value);
            RServiceResult <bool> sessionCheckResult = await _appUserService.SessionExists(userId, sessionId);

            if (!string.IsNullOrEmpty(sessionCheckResult.ExceptionString))
            {
                return(StatusCode((int)HttpStatusCode.Forbidden));
            }

            var res =
                await _ganjoorService.DeleteMyComment(userId, id);

            if (!string.IsNullOrEmpty(res.ExceptionString))
            {
                return(BadRequest(res.ExceptionString));
            }
            if (!res.Result)
            {
                return(NotFound());
            }
            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetSynchronizationQueue()
        {
            Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
            Guid sessionId      = new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value);
            RServiceResult <bool>
            canViewAll =
                await _userPermissionChecker.Check
                (
                    loggedOnUserId,
                    sessionId,
                    RMuseumSecurableItem.AudioRecitationEntityShortName,
                    RMuseumSecurableItem.ModerateOperationShortName
                );

            if (!string.IsNullOrEmpty(canViewAll.ExceptionString))
            {
                return(BadRequest(canViewAll.ExceptionString));
            }
            var res = await _audioService.GetSynchronizationQueue(canViewAll.Result?Guid.Empty : loggedOnUserId);

            if (!string.IsNullOrEmpty(res.ExceptionString))
            {
                return(BadRequest(res.ExceptionString));
            }

            return(Ok(res.Result));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Rotate Image in 90 deg. multiplicants: 90, 180 or 270
        /// </summary>
        /// <param name="id"></param>
        /// <param name="degIn90mul"></param>
        /// <returns></returns>
        public async Task <RServiceResult <RPictureFile> > RotateImage(Guid id, int degIn90mul)
        {
            if (degIn90mul != 90 && degIn90mul != 180 && degIn90mul != 270)
            {
                return(new RServiceResult <RPictureFile>(null, "degIn90mul could only be equal to these 3 values: 90, 180 and 270"));
            }
            RPictureFile rPictureFile =
                await _context.PictureFiles
                .Where(p => p.Id == id)
                .SingleOrDefaultAsync();

            string origPath = GetImagePath(rPictureFile).Result;

            using (MemoryStream msRotated = new MemoryStream())
            {
                using (Image img = Image.FromFile(origPath))
                {
                    img.RotateFlip(degIn90mul == 90 ? RotateFlipType.Rotate90FlipNone : degIn90mul == 180 ? RotateFlipType.Rotate180FlipNone : RotateFlipType.Rotate270FlipNone);

                    ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);

                    Encoder myEncoder =
                        Encoder.Quality;
                    EncoderParameters jpegParameters = new EncoderParameters(1);

                    EncoderParameter qualityParameter = new EncoderParameter(myEncoder, 92L);
                    jpegParameters.Param[0] = qualityParameter;

                    img.Save(msRotated, jpgEncoder, jpegParameters);
                }

                File.Move(GetImagePath(rPictureFile, "thumb").Result, GetImagePath(rPictureFile, "thumb").Result + ".bak");
                File.Move(GetImagePath(rPictureFile, "norm").Result, GetImagePath(rPictureFile, "norm").Result + ".bak");
                File.Move(origPath, origPath + ".bak");

                RServiceResult <RPictureFile>
                result =
                    await ProcessImage
                    (
                        null,
                        rPictureFile,
                        msRotated,
                        rPictureFile.OriginalFileName
                    );

                if (!string.IsNullOrEmpty(result.ExceptionString))
                {
                    return(new RServiceResult <RPictureFile>(null, result.ExceptionString));
                }
                result.Result.LastModified = DateTime.Now;
                _context.PictureFiles.Update(result.Result);
                await _context.SaveChangesAsync();

                File.Delete(GetImagePath(rPictureFile, "thumb").Result + ".bak");
                File.Delete(GetImagePath(rPictureFile, "norm").Result + ".bak");
                File.Delete(origPath + ".bak");

                return(result);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// delete image (from database and file system)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <RServiceResult <bool> > DeleteImage(Guid id)
        {
            try
            {
                RServiceResult <RImage> img = await GetImage(id);

                if (!string.IsNullOrEmpty(img.ExceptionString))
                {
                    return(new RServiceResult <bool>(false, img.ExceptionString));
                }
                if (img.Result == null)
                {
                    return(new RServiceResult <bool>(false, "image not found"));
                }
                File.Delete(GetImagePath(img.Result).Result);
                _context.GeneralImages.Remove(img.Result);
                await _context.SaveChangesAsync();

                return(new RServiceResult <bool>(true));
            }
            catch (Exception exp)
            {
                return(new RServiceResult <bool>(false, exp.ToString()));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> AddSiteBanner()
        {
            try
            {
                if (!Request.Form.TryGetValue("alt", out Microsoft.Extensions.Primitives.StringValues alt))
                {
                    return(BadRequest("alt is null"));
                }
                if (!Request.Form.TryGetValue("url", out Microsoft.Extensions.Primitives.StringValues url))
                {
                    return(BadRequest("url is null"));
                }
                if (Request.Form.Files.Count != 1)
                {
                    return(BadRequest("a single image is not provided"));
                }
                using Stream stream = Request.Form.Files[0].OpenReadStream();
                RServiceResult <GanjoorSiteBannerViewModel> res = await _bannersService.AddSiteBanner(stream, Request.Form.Files[0].FileName, alt.ToString(), url.ToString(), false);

                if (!string.IsNullOrEmpty(res.ExceptionString))
                {
                    return(BadRequest(res.ExceptionString));
                }
                return(Ok(res.Result));
            }
            catch (Exception exp)
            {
                return(BadRequest(exp.ToString()));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add Image File
        /// </summary>
        /// <param name="file"></param>
        /// <param name="stream"></param>
        /// <param name="originalFileNameForStreams"></param>
        /// <param name="imageFolderName"></param>
        /// <returns></returns>
        public async Task <RServiceResult <RImage> > Add(IFormFile file, Stream stream, string originalFileNameForStreams, string imageFolderName)
        {
            try
            {
                RServiceResult <RImage>
                pictureFile =
                    await ProcessImage
                    (
                        file,
                        new RImage()
                {
                    DataTime     = DateTime.Now,
                    LastModified = DateTime.Now,
                    FolderName   = string.IsNullOrEmpty(imageFolderName) ? DateTime.Now.ToString("yyyy-MM") : imageFolderName
                },
                        stream,
                        originalFileNameForStreams
                    );

                if (pictureFile == null)
                {
                    return(new RServiceResult <RImage>(null, pictureFile.ExceptionString));
                }

                return(new RServiceResult <RImage>(pictureFile.Result));
            }
            catch (Exception exp)
            {
                return(new RServiceResult <RImage>(null, exp.ToString()));
            }
        }
        public async Task <IActionResult> GetUserImageBase64(Guid id)
        {
            try
            {
                RServiceResult <RImage> img = await _appUserService.GetUserImage(id);

                if (!string.IsNullOrEmpty(img.ExceptionString))
                {
                    return(BadRequest(img.ExceptionString));
                }
                if (img.Result == null)
                {
                    return(new ObjectResult(string.Empty));
                }

                RServiceResult <string> imgPath = _imageFileService.GetImagePath(img.Result);
                if (!string.IsNullOrEmpty(imgPath.ExceptionString))
                {
                    return(BadRequest(imgPath.ExceptionString));
                }


                return(new ObjectResult(Convert.ToBase64String(System.IO.File.ReadAllBytes(imgPath.Result))));
            }
            catch (Exception exp)
            {
                return(BadRequest(exp.ToString()));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> GetXMLFile(int id)
        {
            RServiceResult <RecitationViewModel> narration =
                await _audioService.Get(id);

            if (!string.IsNullOrEmpty(narration.ExceptionString))
            {
                return(BadRequest(narration.ExceptionString));
            }

            if (narration.Result == null)
            {
                return(NotFound());
            }

            Response.GetTypedHeaders().LastModified = narration.Result.UploadDate;//TODO: Add a FileLastUpdated field to narrations to indicate the last time the mp3/xml files have been updated

            var requestHeaders = Request.GetTypedHeaders();

            if (requestHeaders.IfModifiedSince.HasValue &&
                requestHeaders.IfModifiedSince.Value >= narration.Result.UploadDate)
            {
                return(StatusCode(StatusCodes.Status304NotModified));
            }

            return(new FileStreamResult(new FileStream(narration.Result.LocalXmlFilePath, FileMode.Open, FileAccess.Read), "text/xml"));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// finalize signup and assign his or him comments to him or her
        /// </summary>
        /// <param name="email"></param>
        /// <param name="secret"></param>
        /// <param name="password"></param>
        /// <param name="firstName"></param>
        /// <param name="sureName"></param>
        /// <returns></returns>
        public override async Task <RServiceResult <bool> > FinalizeSignUp(string email, string secret, string password, string firstName, string sureName)
        {
            RServiceResult <bool> res = await base.FinalizeSignUp(email, secret, password, firstName, sureName);

            if (res.Result)
            {
                try
                {
                    RMuseumDbContext context = _context as RMuseumDbContext;
                    var user = (await FindUserByEmail(email)).Result;
                    if (user.EmailConfirmed)
                    {
                        var comments = await context.GanjoorComments.Where(c => c.AuthorEmail == email.ToLower()).ToListAsync();

                        if (comments.Count > 0)
                        {
                            foreach (var comment in comments)
                            {
                                comment.UserId = user.Id;
                            }
                            _context.UpdateRange(comments);
                            await _context.SaveChangesAsync();
                        }
                    }
                }
                catch
                {
                    return(new RServiceResult <bool>(true)); //ignore this error! because signup was succesfull
                }
            }
            return(res);
        }
        public async Task <IActionResult> UploadImage()
        {
            try
            {
                if (!Request.Form.TryGetValue("path", out Microsoft.Extensions.Primitives.StringValues path))
                {
                    return(BadRequest("path is null"));
                }

                IFormFile file = Request.Form.Files[0];

                RServiceResult <RImage> image = await _pictureFileService.Add(file, null, file.FileName, path);


                if (!string.IsNullOrEmpty(image.ExceptionString))
                {
                    return(BadRequest(image.ExceptionString));
                }

                image = await _pictureFileService.Store(image.Result);

                if (!string.IsNullOrEmpty(image.ExceptionString))
                {
                    return(BadRequest(image.ExceptionString));
                }

                return(Ok(image.Result.Id));
            }
            catch (Exception exp)
            {
                return(BadRequest(exp.ToString()));
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> UploadReciation(bool replace = false)
        {
            try
            {
                if (!_audioService.UploadEnabled)
                {
                    return(BadRequest("ارسال خوانش جدید به دلیل تغییرات فنی سایت موقتاً غیرفعال است."));
                }
                Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
                RServiceResult <UploadSession> resSession = await _audioService.InitiateNewUploadSession(loggedOnUserId, replace);

                if (!string.IsNullOrEmpty(resSession.ExceptionString))
                {
                    return(BadRequest(resSession.ExceptionString));
                }
                List <UploadSessionFile> files = new List <UploadSessionFile>();
                foreach (IFormFile file in Request.Form.Files)
                {
                    RServiceResult <UploadSessionFile> rsFileResult = await _audioService.SaveUploadedFile(file);

                    if (!string.IsNullOrEmpty(rsFileResult.ExceptionString))
                    {
                        return(BadRequest(rsFileResult.ExceptionString));
                    }
                    files.Add(rsFileResult.Result);
                }
                resSession = await _audioService.FinalizeNewUploadSession(resSession.Result, files.ToArray());

                return(Ok(resSession.Result));
            }
            catch (Exception exp)
            {
                return(BadRequest(exp.ToString()));
            }
        }
Ejemplo n.º 13
0
        public override async Task <IActionResult> ReLogin(
            Guid sessionId
            )
        {
            string clientIPAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
            RServiceResult <LoggedOnUserModel> res = await _appUserService.ReLogin(sessionId, clientIPAddress);

            if (res.Result == null)
            {
                return(BadRequest(res.ExceptionString));
            }

            var l = res.Result;

            bool keepHistory = false;
            var  kRes        = await _optionsService.GetValueAsync("KeepHistory", l.User.Id);

            if (!string.IsNullOrEmpty(kRes.Result))
            {
                bool.TryParse(kRes.Result, out keepHistory);
            }


            LoggedOnUserModelEx loggedOnUserModelEx = new LoggedOnUserModelEx()
            {
                User          = l.User,
                Token         = l.Token,
                SessionId     = l.SessionId,
                SecurableItem = l.SecurableItem,
                KeepHistory   = keepHistory
            };

            return(Ok(loggedOnUserModelEx));
        }
        public async Task <IActionResult> Get(Guid id)
        {
            RServiceResult <RImage> img =
                await _pictureFileService.GetImage(id);

            if (!string.IsNullOrEmpty(img.ExceptionString))
            {
                return(BadRequest(img.ExceptionString));
            }

            if (img.Result == null)
            {
                return(NotFound());
            }

            Response.GetTypedHeaders().LastModified = img.Result.LastModified;

            var requestHeaders = Request.GetTypedHeaders();

            if (requestHeaders.IfModifiedSince.HasValue &&
                requestHeaders.IfModifiedSince.Value >= img.Result.LastModified)
            {
                return(StatusCode(StatusCodes.Status304NotModified));
            }

            RServiceResult <string> imgPath = _pictureFileService.GetImagePath(img.Result);

            if (!string.IsNullOrEmpty(imgPath.ExceptionString))
            {
                return(BadRequest(imgPath.ExceptionString));
            }


            return(new FileStreamResult(new FileStream(imgPath.Result, FileMode.Open, FileAccess.Read), "image/jpeg"));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Add site banner
        /// </summary>
        /// <param name="imageStream"></param>
        /// <param name="fileName"></param>
        /// <param name="alternateText"></param>
        /// <param name="targetUrl"></param>
        /// <param name="active"></param>
        /// <returns></returns>
        public async Task <RServiceResult <GanjoorSiteBannerViewModel> > AddSiteBanner(Stream imageStream, string fileName, string alternateText, string targetUrl, bool active)
        {
            RServiceResult <RImage> image = await _imageFileService.Add(null, imageStream, fileName, "SiteBanners");

            if (!string.IsNullOrEmpty(image.ExceptionString))
            {
                return(new RServiceResult <GanjoorSiteBannerViewModel>(null, image.ExceptionString));
            }

            GanjoorSiteBanner banner = new GanjoorSiteBanner()
            {
                RImage        = image.Result,
                AlternateText = alternateText,
                TargetUrl     = targetUrl,
                Active        = active
            };

            _context.GanjoorSiteBanners.Add(banner);
            await _context.SaveChangesAsync();

            await CleanBannersCache();

            return(new RServiceResult <GanjoorSiteBannerViewModel>
                   (
                       new GanjoorSiteBannerViewModel()
            {
                Id = banner.Id,
                ImageUrl = $"api/rimages/{banner.RImageId}.jpg",
                AlternateText = banner.AlternateText,
                TargetUrl = banner.TargetUrl,
                Active = banner.Active
            }
                   ));
        }
        public async Task <IActionResult> GetUserSessions(Guid?userId)
        {
            Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);

            if (loggedOnUserId != userId)
            {
                RServiceResult <bool> canViewAllUsersInformation =
                    await _userPermissionChecker.Check
                    (
                        loggedOnUserId,
                        new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value),
                        SecurableItem.UserEntityShortName,
                        SecurableItem.SessionsOperationShortName
                    );

                if (!string.IsNullOrEmpty(canViewAllUsersInformation.ExceptionString))
                {
                    return(BadRequest(canViewAllUsersInformation.ExceptionString));
                }

                if (!canViewAllUsersInformation.Result)
                {
                    return(Forbid());
                }
            }
            RServiceResult <PublicRUserSession[]> sessionsInfo = await _appUserService.GetUserSessions(userId);

            if (sessionsInfo.Result == null)
            {
                return(BadRequest(sessionsInfo.ExceptionString));
            }
            return(Ok(sessionsInfo.Result));
        }
        /// <summary>
        /// check to see if user has permission to do operation
        /// </summary>
        /// <param name="userId">userId</param>
        /// <param name="sessionId"></param>
        /// <param name="securableItemShortName">form</param>
        /// <param name="operationShortName">operation</param>
        /// <returns>true if has permission</returns>
        public virtual async Task <RServiceResult <bool> > Check(Guid userId, Guid sessionId, string securableItemShortName, string operationShortName)
        {
            try
            {
                RServiceResult <PublicRAppUser> userInfo = await _appUserService.GetUserInformation(userId);

                if (userInfo.Result == null)
                {
                    return(new RServiceResult <bool>(false));
                }

                if (userInfo.Result.Status != RAppUserStatus.Active)
                {
                    return(new RServiceResult <bool>(false));
                }

                RServiceResult <bool> sessionCheckResult = await _appUserService.SessionExists(userId, sessionId);

                if (!string.IsNullOrEmpty(sessionCheckResult.ExceptionString))
                {
                    return(new RServiceResult <bool>(false, sessionCheckResult.ExceptionString));
                }

                if (!sessionCheckResult.Result)
                {
                    return(new RServiceResult <bool>(false));
                }



                RServiceResult <bool> isAdminResult = await _appUserService.IsAdmin(userId);

                if (!string.IsNullOrEmpty(isAdminResult.ExceptionString))
                {
                    return(new RServiceResult <bool>(false, isAdminResult.ExceptionString));
                }

                if (isAdminResult.Result)
                {
                    return(new RServiceResult <bool>(true));
                }



                RServiceResult <bool> hasPermission =
                    await _appUserService.HasPermission(userId, securableItemShortName, operationShortName);

                if (hasPermission.Result)
                {
                    return(new RServiceResult <bool>(true));
                }

                return(new RServiceResult <bool>(false));
            }
            catch (Exception exp)
            {
                return(new RServiceResult <bool>(false, exp.ToString()));
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Generated Cropped Image Based On ThumbnailCoordinates For Notes
        /// </summary>
        /// <param name="id"></param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public async Task <RServiceResult <RImage> > GenerateCroppedImageBasedOnThumbnailCoordinates(Guid id, decimal left, decimal top, decimal width, decimal height)
        {
            try
            {
                RPictureFile rPictureFile =
                    await _context.PictureFiles
                    .Where(p => p.Id == id)
                    .SingleOrDefaultAsync();

                int adjustedImageWidth = (int)(width * rPictureFile.NormalSizeImageWidth / rPictureFile.ThumbnailImageWidth);
                if (adjustedImageWidth > rPictureFile.ThumbnailImageWidth)
                {
                    adjustedImageWidth = rPictureFile.ThumbnailImageWidth;
                }

                int adjustedImageHeight = (int)(height * adjustedImageWidth / width);
                int adjusttedLeft       = (int)(left * adjustedImageWidth / width);
                int adjusttedTop        = (int)(top * adjustedImageHeight / height);

                string normalImagePath = GetImagePath(rPictureFile, "norm").Result;
                using (Image targetImage = new Bitmap(adjustedImageWidth, adjustedImageHeight))
                {
                    using (Graphics g = Graphics.FromImage(targetImage))
                    {
                        using (Image img = Image.FromFile(normalImagePath))
                        {
                            g.DrawImage(img, new Rectangle(0, 0, adjustedImageWidth, adjustedImageHeight),
                                        (int)(left * rPictureFile.NormalSizeImageWidth / rPictureFile.ThumbnailImageWidth),
                                        (int)(top * rPictureFile.NormalSizeImageHeight / rPictureFile.ThumbnailImageHeight),
                                        (int)(width * rPictureFile.NormalSizeImageWidth / rPictureFile.ThumbnailImageWidth),
                                        (int)(height * rPictureFile.NormalSizeImageHeight / rPictureFile.ThumbnailImageHeight),
                                        GraphicsUnit.Pixel,
                                        new ImageAttributes()
                                        );
                        }
                    }
                    using (MemoryStream ms = new MemoryStream())
                    {
                        targetImage.Save(ms, ImageFormat.Jpeg);
                        ms.Position = 0;
                        RServiceResult <RImage> res = await _simpleImageStorage.Add(null, ms, $"{Path.GetFileNameWithoutExtension(rPictureFile.OriginalFileName)}-cropped-{left}-{top}-{width}-{height}.jpg", "CroppedImages");

                        if (string.IsNullOrEmpty(res.ExceptionString))
                        {
                            RImage image = res.Result;
                            _context.GeneralImages.Add(image);
                            await _context.SaveChangesAsync();

                            return(new RServiceResult <RImage>(image));
                        }
                        return(res);
                    }
                }
            }
            catch (Exception exp)
            {
                return(new RServiceResult <RImage>(null, exp.ToString()));
            }
        }
Ejemplo n.º 19
0
 public async Task<IActionResult> DeleteAllReadNotification()
 {
     Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
     RServiceResult<bool> res = await _notificationService.DeleteNotification(Guid.Empty, loggedOnUserId);
     if (!string.IsNullOrEmpty(res.ExceptionString))
         return BadRequest(res.ExceptionString);
     return Ok();
 }
Ejemplo n.º 20
0
 public async Task<IActionResult> SetAllNotificationsStatusRead()
 {
     Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
     RServiceResult<bool> res = await _notificationService.SetAllNotificationsStatus(loggedOnUserId, NotificationStatus.Read);
     if (!string.IsNullOrEmpty(res.ExceptionString))
         return BadRequest(res.ExceptionString);
     return Ok();
 }
Ejemplo n.º 21
0
 public async Task<IActionResult> SwitchNotificationStatus(Guid notificationId)
 {
     Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
     RServiceResult<RUserNotificationViewModel> res = await _notificationService.SwitchNotificationStatus(notificationId, loggedOnUserId);
     if (!string.IsNullOrEmpty(res.ExceptionString))
         return BadRequest(res.ExceptionString);
     return Ok(res.Result);
 }
Ejemplo n.º 22
0
 public async Task<IActionResult> GetUnreadUserNotificationsCount()
 {
     Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
     RServiceResult<int> res = await _notificationService.GetUnreadUserNotificationsCount(loggedOnUserId);
     if (!string.IsNullOrEmpty(res.ExceptionString))
         return BadRequest(res.ExceptionString);
     return Ok(res.Result);
 }
Ejemplo n.º 23
0
        public async Task <IActionResult> ModeratePoemNarration(int id, [FromBody] RecitationModerateViewModel model)
        {
            if (!_audioService.UploadEnabled)
            {
                return(BadRequest("این قابلیت به دلیل تغییرات فنی سایت موقتاً غیرفعال است."));
            }

            Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);

            var narration = await _audioService.Get(id);

            if (!string.IsNullOrEmpty(narration.ExceptionString))
            {
                return(BadRequest(narration.ExceptionString));
            }

            if (narration.Result == null)
            {
                return(NotFound());
            }

            if (narration.Result.Owner.Id != loggedOnUserId)
            {
                Guid sessionId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value);
                RServiceResult <bool>
                serviceResult =
                    await _userPermissionChecker.Check
                    (
                        loggedOnUserId,
                        sessionId,
                        RMuseumSecurableItem.AudioRecitationEntityShortName,
                        RMuseumSecurableItem.ModerateOperationShortName
                    );

                if (!string.IsNullOrEmpty(serviceResult.ExceptionString))
                {
                    return(BadRequest(serviceResult.ExceptionString));
                }

                if (!serviceResult.Result)
                {
                    return(StatusCode((int)HttpStatusCode.Forbidden));
                }
            }

            var res = await _audioService.ModeratePoemNarration(id, loggedOnUserId, model);

            if (!string.IsNullOrEmpty(res.ExceptionString))
            {
                if (res.ExceptionString == "404")
                {
                    return(NotFound());
                }
                return(BadRequest(res.ExceptionString));
            }

            return(Ok(res.Result));
        }
        public async Task <IActionResult> FinalizeSignUp([AuditIgnore][FromBody] VerifiedSignUpViewModel newUserInfo)
        {
            RServiceResult <bool> result = await _appUserService.FinalizeSignUp(newUserInfo.Email, newUserInfo.Secret, newUserInfo.Password, newUserInfo.FirstName, newUserInfo.SureName);

            if (!result.Result)
            {
                return(BadRequest(result.ExceptionString));
            }
            return(Ok(true));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> SetRoleSecurableItemsStatus(string roleName, [FromBody] SecurableItem[] securableItems)
        {
            RServiceResult <bool> res = await _roleService.SetRoleSecurableItemsStatus(roleName, securableItems);

            if (!res.Result)
            {
                return(BadRequest(res.ExceptionString));
            }
            return(Ok(res.Result));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Post([FromBody] RAppRole newGroupInfo)
        {
            RServiceResult <RAppRole> result = await _roleService.AddRole(newGroupInfo);

            if (result.Result == null)
            {
                return(BadRequest(result.ExceptionString));
            }
            return(Ok(result.Result));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Rotate(Guid id, int degIn90mul)
        {
            RServiceResult <RPictureFile> res = await _pictureFileService.RotateImage(id, degIn90mul);

            if (!string.IsNullOrEmpty(res.ExceptionString))
            {
                return(BadRequest(res.ExceptionString));
            }
            return(Ok(res.Result));
        }
        /// <summary>
        /// can current user read this userId daya
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        protected async Task <RServiceResult <bool> > CanReadUserData(Guid userId)
        {
            RServiceResult <Guid> scopeForUserId = await GetUserIdUnlessUserHavePermissionToReadAllUsersDataWhichReturnEmptyUserId();

            if (!string.IsNullOrEmpty(scopeForUserId.ExceptionString))
            {
                return(new RServiceResult <bool>(false, scopeForUserId.ExceptionString));
            }
            return(new RServiceResult <bool>(scopeForUserId.Result == Guid.Empty || scopeForUserId.Result == userId));
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> GenerateCroppedImageBasedOnThumbnailCoordinates(Guid id, decimal left, decimal top, decimal width, decimal height)
        {
            RServiceResult <RImage> cropped = await _pictureFileService.GenerateCroppedImageBasedOnThumbnailCoordinates(id, left, top, width, height);

            if (!string.IsNullOrEmpty(cropped.ExceptionString))
            {
                return(BadRequest(cropped.ExceptionString));
            }
            return(Ok(cropped.Result));
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> Get()
        {
            RServiceResult <RAppRole[]> rolesInfo = await _roleService.GetAllRoles();

            if (rolesInfo.Result == null)
            {
                return(BadRequest(rolesInfo.ExceptionString));
            }
            return(Ok(rolesInfo.Result));
        }