Example #1
0
        public int Create(PostDTO item)
        {
            Mapper.CreateMap<PostDTO, Post>();

            int result = Database.Posts.Create(Mapper.Map<PostDTO, Post>(item)).Id;
            Database.Save();
            return result;
        }
Example #2
0
        public void CreatePost(PostDTO post)
        {
            post.created = DateTime.Now;
            post.modified = DateTime.Now;
            int newPostId = _postSvc.Create(post); // i need new post id for next actions

            var names = post.picturesName.ToArray();
            UserDTO user = _userSvc.Get(post.userId);

            string rootPath = HttpContext.Current.Request.MapPath("~/Temp/");
            string tempDirectoryPath = Path.Combine(rootPath, user.email);

            rootPath = HttpContext.Current.Request.MapPath("~/Pictures/");
            string userDirectoryPath = Path.Combine(rootPath, user.email);
            if (!Directory.Exists(userDirectoryPath))
            {
                string standartImageDirectoryPath = Path.Combine(userDirectoryPath, "Standart");
                string mediumImageDirectoryPath = Path.Combine(userDirectoryPath, "Medium");
                string smallImageDirectoryPath = Path.Combine(userDirectoryPath, "Small");
                Directory.CreateDirectory(userDirectoryPath);
                Directory.CreateDirectory(standartImageDirectoryPath);
                Directory.CreateDirectory(mediumImageDirectoryPath);
                Directory.CreateDirectory(smallImageDirectoryPath);
            }

            if (Directory.Exists(tempDirectoryPath))
            {
                var httpRequest = HttpContext.Current.Request;
                if (names.Length > 0)
                {
                    foreach (string name in names)
                    {
                        try
                        {
                            if (!File.Exists(tempDirectoryPath + "/Standart/" + name))
                            {
                                using (FileStream fs = File.Create(tempDirectoryPath + "/Standart/" + name)) { }
                            }
                            File.Move(tempDirectoryPath + "/Standart/" + name, userDirectoryPath + "/Standart/" + name);
                            File.Move(tempDirectoryPath + "/Medium/" + name, userDirectoryPath + "/Medium/" + name);
                            File.Move(tempDirectoryPath + "/Small/" + name, userDirectoryPath + "/Small/" + name);
                        }
                        catch (Exception e)
                        {
                            throw new Exception("file has not been moved", e.InnerException);
                        }

                        IEnumerable<AlbumDTO> albums = _userSvc.GetUserAlbums(post.userId);

                        _pictureSvc.Create(new PictureDTO
                        {
                            urlStandart = Convert.ToString("Pictures/" + user.email + "/Standart/" + name),
                            urlMedium = Convert.ToString("Pictures/" + user.email + "/Medium/" + name),
                            urlSmall = Convert.ToString("Pictures/" + user.email + "/Small/" + name),
                            postId = newPostId,
                            userId = post.userId,
                            likes = 0,
                            albumId = albums.First().id
                        });
                    }
                }
            }
            else
            {
                throw new Exception();
            }
        }
Example #3
0
 public void Update(PostDTO item)
 {
 }