示例#1
0
        public async Task <ActionResult <StaffCreateModel> > PostAsync([FromBody] StaffCreateModel employee)
        {
            // var employeeNewID = employee with { Id = null };
            // Mapping By Mapster
            var newEmployee = employee.Adapt <Staff>();

            await _staffRepository.CreateAsync(newEmployee);

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = newEmployee.Id }, newEmployee));
        }
示例#2
0
        public async Task <ActionResult> Create(StaffCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_Create", model: model));
            }

            var result = await _httpClientService.SendRequest("api/admin", HttpMethod.Post, model);

            if (result.IsSuccessStatusCode)
            {
                return(NotificationSuccessResult(Resource.RecordAddSuccess, Url.RouteUrl(StaffRoutes.Data)));
            }

            var errorMessage = await _commonService.CheckForValidationErrors(result, Resource.ApplicationErrorText);

            return(NotificationErrorResult(errorMessage, Url.RouteUrl(StaffRoutes.Data)));
        }