Esempio n. 1
0
        public ActionResult AddAttendance()
        {
            var model = new AttendanceRecordViewModel()
            {
                Employees = db.Employees.ToList()
            };

            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([FromBody] AttendanceRecordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var result = await attendanceService.CreateAsync(model);

                return(CreatedAtAction(nameof(GetOne), new { id = result.Id }, result));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Esempio n. 3
0
        public async Task <AttendanceRecord> CreateAsync(AttendanceRecordViewModel model)
        {
            // Create the entity
            var toCreate = mapper.Map <AttendanceRecord>(model);

            // Send to repository
            var created = await repository.CreateAsync(toCreate);

            if (created == null)
            {
                throw new Exception();
            }

            // Save changes
            await repository.SaveChangesAsync();

            return(created);
        }