예제 #1
0
        public Author Register(Author author, HttpPostedFileWrapper file)
        {
            try
            {
                if (file != null)
                {
                    if (IsImage(file.ContentType))
                    {
                        var imageName         = Path.GetFileName(file?.FileName);
                        var formattedImgTitle = $"{author.Name}-{author.Surname}-{imageName}";

                        var imagesPath = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/Authors/"), formattedImgTitle);
                        file.SaveAs(imagesPath);

                        author.ProfileImage = formattedImgTitle;
                    }
                }

                author.Password = _securirtyService.Encrypt(author.Password);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            _topBloggersDb.Authors.Add(author);
            _topBloggersDb.SaveChanges();

            return(author);
        }
예제 #2
0
        public void IncrementArticleView(Article article)
        {
            article.Views += 1;

            _topBloggersDb.Entry(article).State = EntityState.Modified;
            _topBloggersDb.SaveChanges();
        }