/// <summary> /// Crear registro de PersonServices /// Autor: Jair Guerrero /// Fecha: 2021-02-20 /// </summary> public long Create(PersonServicesAM entity) { try { var PersonServices = mapper.Map <PersonServices>(entity); IRepository <PersonServices> repo = new PersonServicesRepo(context); return(repo.Create(PersonServices)); } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } }
public async Task <IActionResult> RegisterHours(PersonServicesAM model) { if (ModelState.IsValid) { var apiEndpoint = Configuration["ApiEndpoint"]; var apiClient = new HttpClient(); int result = DateTime.Compare(model.EndDate.Value, model.StarDate.Value); if (result < 0) { ModelState.AddModelError("StarDate", "La fecha de inicio debe ser menor que la fecha de fin."); return(View(model)); } var service = servicesBO.GetFirst(j => j.Identification == model.Services.Identification); model.IdUser = AuthUser.Id; model.IdPerson = AuthUser.IdPerson.Value; model.IdServices = service.Id; model.Services = null; var currentCulture = CultureInfo.CurrentCulture; model.WeekNumber = currentCulture.Calendar.GetWeekOfYear( model.StarDate.Value, currentCulture.DateTimeFormat.CalendarWeekRule, currentCulture.DateTimeFormat.FirstDayOfWeek); HttpContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = await apiClient.PostAsync(apiEndpoint + "/api/Report/RegisterHours", content); if (response.IsSuccessStatusCode) { CreateModal("exito", "Terminado", "Las horas se han registrado satisfactoriamente.", "Terminar", null, "Redirect('Index')", null); } } return(View()); }
public IActionResult RegisterHours([FromBody] PersonServicesAM data) { try { pServiceBO.Create(data); return(StatusCode(StatusCodes.Status201Created, new JsonResponse { Status = StatusCodes.Status201Created, Title = SUCCESFULLY, TraceId = Guid.NewGuid().ToString() })); } catch (Exception e) { logger.LogInformation("Error: {mess}", e); return(StatusCode(StatusCodes.Status500InternalServerError, new JsonResponse { Status = StatusCodes.Status500InternalServerError, Title = INTERNAL_ERROR, Errors = new string[] { e.Message }, TraceId = Guid.NewGuid().ToString() })); } }