Exemplo n.º 1
0
        public async Task <IActionResult> UpdateLeave(int id, [FromBody] InputLeaveDto createLeaveDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var leave = await context.Leaves.Include(x => x.EmployeeLeaves).SingleOrDefaultAsync(x => x.Id == id);

            leave.LastUpdated = DateTime.Now;
            mapper.Map <InputLeaveDto, Leave>(createLeaveDto, leave);

            await context.SaveChangesAsync();

            var result = mapper.Map <Leave, InputLeaveDto>(leave);

            return(Ok(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateLeave([FromBody] InputLeaveDto createLeaveDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var leave = mapper.Map <InputLeaveDto, Leave>(createLeaveDto);

            leave.LastUpdated = DateTime.Now;
            context.Leaves.Add(leave);

            await context.SaveChangesAsync();

            var result = mapper.Map <Leave, InputLeaveDto>(leave);

            return(Ok(result));
        }