Beispiel #1
0
        public async Task <ResultDTO> AddActor([FromBody] ActorAddDTO model)
        {
            try
            {
                var actor = _mapper.Map <ActorAddDTO, Actor>(model);
                await _context.actors.AddAsync(actor);

                await _context.SaveChangesAsync();

                return(new ResultDTO
                {
                    Status = 200,
                    Message = "Posted"
                });
            }
            catch (Exception ex)
            {
                List <string> temp = new List <string>();
                temp.Add(ex.Message);
                return(new ResultErrorDTO
                {
                    Status = 500,
                    Message = "Error",
                    Errors = temp
                });
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Post([FromForm] ActorAddDTO actorAddDTO)
        {
            var actor = mapper.Map <Actor>(actorAddDTO);


            if (actorAddDTO.Photo != null)
            {
                actor.Photo = await storageFile.SaveFiles(container, actorAddDTO.Photo);
            }

            context.Add(actor);

            await context.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #3
0
        public async Task <ActionResult> Put(int id, [FromForm] ActorAddDTO actorAddDTO)
        {
            var actor = await context.Actors.FirstOrDefaultAsync(x => x.id == id);

            if (actor == null)
            {
                return(NotFound());
            }

            actor = mapper.Map(actorAddDTO, actor);

            if (actorAddDTO.Photo != null)
            {
                actor.Photo = await storageFile.EditFiles(container, actorAddDTO.Photo, actor.Photo);
            }

            await context.SaveChangesAsync();

            return(NoContent());
        }