public ActionResult <ApiResponse <Seance> > AddSeance(Seance seance) { string returnError = null; var validations = new List <string>(); var seanceDuration = (seance.EndDate.Ticks - seance.StartDate.Ticks) / 600000000; if (seanceDuration > Convert.ToInt32(seance.Movie.DurationTime)) { seance.Places = new List <Place>(250); for (int i = 0; i < 250; i++) { seance.Places.Add(new Place { IsFree = true, IsSelected = false, Number = i + 1 } as Place); } returnError = (_repository.AddSeance(seance)); if (returnError != null) { validations.Add(returnError); } } else { validations.Add("To short seance."); } ApiResponse <Seance> response = new ApiResponse <Seance> { Data = seance, Token = _token.Generate(), validationMessages = validations }; return(Ok(response)); }
public async Task <SignIn> Authenticate(SignInInput input) { if (input == null) { throw new ArgumentNullException($"{nameof(input)} is null."); } var response = await service.Authenticate(input); if (!response.Succeeded) { throw new NotAuthenticatedException(); } var result = new SignIn { Token = jwtToken.Generate(response.User, response.Roles), Succeeded = response.Succeeded }; // Save to cache await cache.Set(response.User?.Id, result); return(result); }
/// <summary> /// Insert new token on the database /// Example of validate the entity using Abstract Validator /// </summary> /// <param name="obj"></param> /// <returns></returns> public string Post(T obj) { try { var result = Validate(obj); if (!result.IsValid) { throw new ExecptionHelper.ExceptionService(result.Errors[0].ToString()); } var _obj = obj as TokenEntity; string token = _token.Generate(_obj); _repository.Insert(obj); return(token); } catch (ExecptionHelper.ExceptionService ex) { throw new ExecptionHelper.ExceptionService(ex.Message); } }