Пример #1
0
        public async Task <AspNetUsersDocumentViewModel> GetAspNetUserImage()
        {
            try
            {
                UploadFileType filetype = new UploadFileType();

                AspNetUsersDocumentViewModel aspNetUserImage = await this.AspNetUsersDocumentBusinessLayer.GetAllAspNetUsersImage(User.Identity.GetUserId(), UploadFileType.Image);

                aspNetUserImage.FileLocation = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath + ConfigurationManager.AppSettings.Get("ProfileImagesGetLocation") + aspNetUserImage.UserId;
                return(aspNetUserImage);
            }
            catch (Exception ex)
            {
                this.ExceptionLogger.Log(LogLevel.Error, ex);
                throw ex;
            }
        }
Пример #2
0
        public async Task <AspNetUsersDocumentViewModel> Create(AspNetUsersDocumentViewModel documentViewModel)
        {
            AspNetUsersDocumentMapping aspNetUserDocument = ViewModelToEntityMapper.Map(documentViewModel);

            if (aspNetUserDocument != null)
            {
                aspNetUserDocument = this.AspNetUsersDocumentRepository.Add(aspNetUserDocument);
                if (aspNetUserDocument.DocumentId > 0)
                {
                    documentViewModel.DocumentId = aspNetUserDocument.DocumentId;
                }
                else
                {
                    documentViewModel.HasError = true;
                }
            }

            return(documentViewModel);
        }
Пример #3
0
        public async Task <AspNetUsersDocumentViewModel> Update(AspNetUsersDocumentViewModel documentViewModel)
        {
            var aspNetUserDocument = this.AspNetUsersDocumentRepository.Find(documentViewModel.DocumentId);

            if (aspNetUserDocument != null)
            {
                var lastModifiedDate = aspNetUserDocument.LastModifiedOn;
                aspNetUserDocument = this.AspNetUsersDocumentRepository.Update(ViewModelToEntityMapper.Map(documentViewModel, aspNetUserDocument));

                if (lastModifiedDate < aspNetUserDocument.LastModifiedOn)
                {
                    return(documentViewModel);
                }
                else
                {
                    documentViewModel.HasError = true;
                }
            }

            return(documentViewModel);
        }
Пример #4
0
        public static AspNetUsersDocumentMapping Map(AspNetUsersDocumentViewModel viewModel, AspNetUsersDocumentMapping entity)
        {
            if (viewModel == null || entity == null)
            {
                return(null);
            }

            entity.DocumentId      = viewModel.DocumentId;
            entity.UserId          = viewModel.UserId;
            entity.FileType        = viewModel.FileType;
            entity.FileName        = viewModel.FileName;
            entity.FileLocation    = viewModel.FileLocation;
            entity.FileDisplayName = viewModel.FileDisplayName;
            entity.CreatedBy       = viewModel.CreatedBy;
            entity.CreatedOn       = viewModel.CreatedOn;
            entity.LastModifiedBy  = viewModel.LastModifiedBy;
            entity.LastModifiedOn  = viewModel.LastModifiedOn;
            entity.IsActive        = viewModel.IsActive;

            return(entity);
        }
Пример #5
0
        public static AspNetUsersDocumentMapping Map(AspNetUsersDocumentViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(null);
            }

            return(new AspNetUsersDocumentMapping
            {
                DocumentId = viewModel.DocumentId,
                UserId = viewModel.UserId,
                FileType = viewModel.FileType,
                FileName = viewModel.FileName,
                FileLocation = viewModel.FileLocation,
                FileDisplayName = viewModel.FileDisplayName,
                CreatedBy = viewModel.CreatedBy,
                CreatedOn = viewModel.CreatedOn,
                LastModifiedBy = viewModel.LastModifiedBy,
                LastModifiedOn = viewModel.LastModifiedOn,
                IsActive = viewModel.IsActive
            });
        }
Пример #6
0
        public async Task <ActionResult> UploadProfileImages(string userId, UploadFileType fileType, IEnumerable <HttpPostedFileBase> profileImages)
        {
            try
            {
                if (profileImages != null && profileImages.Any())
                {
                    string[] allowedFileExtensions = ConfigurationManager.AppSettings.Get("AllowedImageExtension").Split(',');
                    string   fileUploadLocation    = ConfigurationManager.AppSettings.Get("ProfileImagesUploadLocation");

                    if (!string.IsNullOrWhiteSpace(fileUploadLocation))
                    {
                        fileUploadLocation = Server.MapPath(Path.Combine(fileUploadLocation, userId.ToString()));

                        if (!Directory.Exists(fileUploadLocation))
                        {
                            Directory.CreateDirectory(fileUploadLocation);
                        }

                        foreach (HttpPostedFileBase postedFile in profileImages)
                        {
                            if (postedFile.ContentLength > 0 && allowedFileExtensions.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
                            {
                                // string uploadFileName = String.Format("{0}{1}", "photo", Path.GetExtension(postedFile.FileName));
                                string uploadFileName = String.Format("{0}{1}", Guid.NewGuid(), Path.GetExtension(postedFile.FileName));
                                // string uploadFileName = "photo";
                                string filePath = Path.Combine(fileUploadLocation, uploadFileName);

                                switch (fileType)
                                {
                                case UploadFileType.Image:
                                    AspNetUsersDocumentViewModel documentViewModel = new AspNetUsersDocumentViewModel
                                    {
                                        UserId          = userId,
                                        FileType        = fileType.ToString(),
                                        FileName        = uploadFileName,
                                        FileLocation    = fileUploadLocation,
                                        FileDisplayName = postedFile.FileName,
                                        CreatedBy       = User.Identity.GetUserId(),
                                        CreatedOn       = DateTime.Now,
                                        LastModifiedBy  = User.Identity.GetUserId(),
                                        LastModifiedOn  = DateTime.Now,
                                        IsActive        = true
                                    };
                                    documentViewModel = await AspNetUsersDocumentBusinessLayer.Create(documentViewModel);

                                    if (documentViewModel.DocumentId > 0)
                                    {
                                        postedFile.SaveAs(filePath);
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }

                    return(Content(""));
                }
            }
            catch (Exception ex)
            {
                this.ExceptionLogger.Log(LogLevel.Error, ex);
                throw ex;
            }

            return(null);
        }