Ejemplo n.º 1
0
 public IActionResult Post([FromBody] WriterDto dto)
 {
     try
     {
         addWriter.Execute(dto);
         return(StatusCode(201));
     }
     catch (EntityAlreadyExistsException e)
     {
         return(StatusCode(409, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
     catch (Exception e)
     {
         return(StatusCode(500, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
 }
Ejemplo n.º 2
0
 public ActionResult Create(WriterDto dto)
 {
     if (!ModelState.IsValid)
     {
         TempData["error"] = "Check your input.";
         return(RedirectToAction(nameof(Create)));
     }
     try
     {
         executor.ExecuteCommand(addWriter, dto);
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityNotAllowedException)
     {
         return(RedirectToAction("PageNotFound", "Redirections"));
     }
     catch (EntityAlreadyExistsException e)
     {
         TempData["error"] = e.Message;
     }
     catch (Exception e)
     {
         TempData["error"] = e.Message;
     }
     return(RedirectToAction(nameof(Index)));
 }
Ejemplo n.º 3
0
        public WriterDto Execute(int search)
        {
            var query = _context.Writers.Include(x => x.WriterMovies)
                        .ThenInclude(x => x.Movie)
                        .ThenInclude(x => x.Genre)
                        .AsQueryable();
            var writer = query.FirstOrDefault(a => a.Id == search);

            if (writer == null)
            {
                throw new EntityNotFoundException(search, typeof(Writer));
            }
            var response = new WriterDto
            {
                Id           = writer.Id,
                FirstName    = writer.FirstName,
                LastName     = writer.LastName,
                Oscars       = writer.Oscars ?? 0,
                FullName     = writer.FirstName + " " + writer.LastName,
                MovieNumber  = writer.WriterMovies.Count(),
                WriterMovies = writer.WriterMovies.Select(x => new WriterMovieDto
                {
                    Id     = x.MovieId,
                    Genre  = x.Movie.Genre.Name,
                    Title  = x.Movie.Title,
                    Price  = x.Movie.Price,
                    Oscars = x.Movie.Oscars ?? 0,
                    Year   = x.Movie.Year
                })
            };

            return(response);
        }
Ejemplo n.º 4
0
        public IActionResult UpdateWriter([FromBody] WriterDto writer)
        {
            var result = service.UpdateWriter(writer);

            if (result)
            {
                return(Ok(true));
            }
            return(BadRequest(false));
        }
        public async Task <ActionResult <WriterDto> > PostWriter(WriterDto writerDto)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            var result = await this.writersService.Add(writerDto);

            writerDto.Id = result;

            return(CreatedAtAction("GetWriter", new { id = result }, writerDto));
        }
Ejemplo n.º 6
0
        public void Execute(WriterDto request)
        {
            if (Context.Writers.Any(w => w.Name.ToLower() == request.Name.ToLower()))
            {
                throw new EntityAlreadyExistsException("Writer");
            }

            Context.Writers.Add(new Writer
            {
                Name = request.Name
            });

            Context.SaveChanges();
        }
Ejemplo n.º 7
0
 public bool WriterLogin(WriterDto writerLoginDto)
 {
     using (var hmac = new System.Security.Cryptography.HMACSHA512())
     {
         var writer = _writerService.fetchWriterList();
         foreach (var item in writer)
         {
             if (HashingHelper.WriterVerifyPasswordHash(writerLoginDto.WriterPassword, item.WriterPasswordHash, item.WriterPasswordSalt))
             {
                 return(true);
             }
         }
         return(false);
     }
 }
        public async Task <int> Add(WriterDto input)
        {
            var writer = new Writer()
            {
                Name        = input.Name,
                Pseudonym   = input.Pseudonym,
                DateOfBirth = input.DateOfBirth,
            };

            await this.repository.AddAsync(writer);

            await this.repository.SaveChangesAsync();

            return(writer.Id);
        }
        public bool DeleteArticle(ArticleDto todetele, WriterDto writer)
        {
            Utils.SendObject(Constants.DeleteArticleCommand, _stream);
            var response         = Utils.ReadObject <string>(_stream);
            var articleUpdateDto = new ArticleUpdateDto
            {
                ArticleDto = todetele,
                WriterDto  = writer
            };

            Utils.SendObject(articleUpdateDto, _stream);
            var finalResponse = Utils.ReadObject <string>(_stream);

            return(finalResponse == Constants.Success);
        }
        public bool UpdateArticle(ArticleDto updated, ArticleDto original, WriterDto writer)
        {
            Utils.SendObject(Constants.UpdateArticleCommand, _stream);
            var response = Utils.ReadObject <string>(_stream);

            updated.Id = original.Id;
            var articleUpdateDto = new ArticleUpdateDto
            {
                ArticleDto = updated,
                WriterDto  = writer
            };

            Utils.SendObject(articleUpdateDto, _stream);
            var finalResponse = Utils.ReadObject <string>(_stream);

            return(finalResponse == Constants.Success);
        }
Ejemplo n.º 11
0
        public void Execute(WriterDto request)
        {
            var writer = Context.Writers.Find(request.Id);

            if (writer == null || writer.IsDeleted == true)
            {
                throw new EntityNotFoundException("Writer");
            }

            if (writer.Name.ToLower() != request.Name.ToLower() && Context.Writers.Any(w => w.Name.ToLower() == request.Name.ToLower()))
            {
                throw new EntityAlreadyExistsException("Writer");
            }

            writer.Name = request.Name;

            Context.SaveChanges();
        }
Ejemplo n.º 12
0
        public bool UpdateWriter(WriterDto writerDto)
        {
            var writer = context.Writers.FirstOrDefault(w => w.Id == writerDto.Id);

            writer.City         = writerDto.City;
            writer.Description  = writerDto.Description ?? "";
            writer.DisplayName  = writerDto.DisplayName;
            writer.EmailAddress = writerDto.EmailAddress;
            writer.Job          = writerDto.Job;
            writer.Updated      = DateTime.Now;
            var result1 = context.SaveChanges() > 0;

            var socialAccounts = context.SocialAccounts.Include(s => s.SocialType).Where(s => s.WriterId == writerDto.Id).ToList();

            foreach (var item in writerDto.SocialAccounts)
            {
                var _socialAccount = socialAccounts.FirstOrDefault(w => w.SocialType.Name == item.Name);
                if (_socialAccount != null)
                {
                    _socialAccount.Url = item.Url;
                }
                else
                {
                    var newSocialAccount = new SocialAccount
                    {
                        Id        = Guid.NewGuid(),
                        Created   = DateTime.Now,
                        IsActive  = true,
                        IsDeleted = false,
                        TypeId    = context.SocialTypes.First(w => w.Name == item.Name).Id,
                        Updated   = DateTime.Now,
                        Url       = item.Url,
                        WriterId  = writerDto.Id
                    };
                    context.SocialAccounts.Add(newSocialAccount);
                }
            }
            context.SaveChanges();


            return(result1);
        }
        public async Task <bool> Update(int id, WriterDto writerDto)
        {
            var writer = this.repository.All()
                         .Where(x => x.Id == id)
                         .FirstOrDefault();

            if (writer == null)
            {
                return(false);
            }

            this.mapper.Map <WriterDto, Writer>(writerDto, writer);
            writer.Id = id;


            this.repository.Update(writer);
            await this.repository.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> PutWriter(int id, WriterDto writerDto)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            writerDto.Id = id;


            var result = await this.writersService.Update(id, writerDto);

            if (result == false)
            {
                return(this.BadRequest());
            }


            return(CreatedAtAction("GetWriter", new { id = id }, writerDto));
        }
Ejemplo n.º 15
0
        public ActionResult WriterLogin(WriterDto writerLoginDto)
        {
            var          response = Request["g-recaptcha-response"];
            const string secret   = "6LePpV4bAAAAAFqD4a22ld2SmH4hE8_Sb2SAfm6R";
            var          client   = new WebClient();
            var          reply    =
                client.DownloadString(
                    string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, response));
            var captchaResponse = JsonConvert.DeserializeObject <CaptchaResult>(reply);

            if (authService.WriterLogin(writerLoginDto) && captchaResponse.Success)
            {
                FormsAuthentication.SetAuthCookie(writerLoginDto.WriterMail, false);
                Session["WriterMail"] = writerLoginDto.WriterMail;
                return(RedirectToAction("MyContent", "WriterPanelContent"));
            }
            else
            {
                ViewData["ErrorMessage"] = "Kullanıcı adı veya Parola yanlış";
                return(RedirectToAction("WriterLogin"));
            }
        }
Ejemplo n.º 16
0
 public ActionResult Edit(int id, WriterDto dto)
 {
     try
     {
         dto.Id = id;
         executor.ExecuteCommand(editWriter, dto);
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityNotAllowedException)
     {
         return(RedirectToAction("PageNotFound", "Redirections"));
     }
     catch (EntityAlreadyExistsException e)
     {
         TempData["error"] = e.Message;
     }
     catch (Exception e)
     {
         TempData["error"] = e.Message;
     }
     return(RedirectToAction(nameof(Index)));
 }
Ejemplo n.º 17
0
 public IActionResult Put(int id, [FromBody] WriterDto dto)
 {
     try
     {
         dto.Id = id;
         editWriter.Execute(dto);
         return(StatusCode(204));
     }
     catch (EntityAlreadyExistsException e)
     {
         return(StatusCode(409, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
     catch (Exception e)
     {
         return(StatusCode(500, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
 }
Ejemplo n.º 18
0
 public ActionResult WriterRegister(WriterDto writerLoginDto)
 {
     authService.WriterRegister(writerLoginDto.WriterMail, writerLoginDto.WriterPassword);
     return(RedirectToAction("MyContent", "WriterPanelContent"));
 }
Ejemplo n.º 19
0
 public ArticleViewModel()
 {
     Articles          = _client.GetArticleDtos();
     EditingArticleDto = new ArticleDto();
     WriterDto         = new WriterDto();
 }