/// <summary> /// Create/Update product place /// </summary> /// <param name="placeProduct"></param> /// <returns></returns> public virtual async Task <PlaceProduct> SetProductPlace(PlaceProduct placeProduct) { if (placeProduct is null) { throw new ArgumentNullException(nameof(placeProduct)); } if (string.IsNullOrEmpty(placeProduct.PlaceProviderId)) { throw new Exception("Place provider is empty"); } if (string.IsNullOrEmpty(placeProduct.PlaceId)) { throw new Exception("Place is empty"); } if (string.IsNullOrEmpty(placeProduct.ProductId)) { throw new Exception("Product is empty"); } try { await redisCacheClient.Db0.HashSetAsync($"{configuration["db-prefix"]}{REDIS_KEY_PRODUCT_PLACES_OBJECTS}", placeProduct.Id, placeProduct); await redisCacheClient.Db0.SetAddAsync($"{configuration["db-prefix"]}{REDIS_KEY_PRODUCT_PLACES_BY_PP}_{placeProduct.PlaceProviderId}", placeProduct.Id); await redisCacheClient.Db0.SetAddAsync($"{configuration["db-prefix"]}{REDIS_KEY_PRODUCT_PLACES_BY_PLACE}_{placeProduct.PlaceId}", placeProduct.Id); return(placeProduct); } catch (Exception exc) { logger.LogError(exc, exc.Message); throw; } }
protected HttpResponseMessage InsertOrUpdatePlaceProduct(HttpClient client, PlaceProduct placeProduct) { var body = Newtonsoft.Json.JsonConvert.SerializeObject(placeProduct); return(client.PostAsync("Place/InsertOrUpdatePlaceProduct", new System.Net.Http.StringContent(body, Encoding.UTF8, "application/json") ).Result); }
/// <summary> /// DeleteProductPlace /// </summary> /// <param name="placeProduct"></param> /// <returns></returns> public async override Task <bool> DeletePlaceProduct(PlaceProduct placeProduct) { dataPlaceProduct.TryRemove(placeProduct.Id, out var removed); if (removed == null) { return(false); } return(true); }
/// <summary> /// Delete product place /// </summary> /// <param name="placeProduct"></param> /// <returns></returns> public virtual async Task <bool> DeletePlaceProduct(PlaceProduct placeProduct) { if (placeProduct == null) { throw new ArgumentNullException(nameof(placeProduct)); } try { await redisCacheClient.Db0.HashDeleteAsync($"{configuration["db-prefix"]}{REDIS_KEY_PRODUCT_PLACES_OBJECTS}", placeProduct.Id); await redisCacheClient.Db0.SetRemoveAsync($"{configuration["db-prefix"]}{REDIS_KEY_PRODUCT_PLACES_BY_PLACE}_{placeProduct.PlaceId}", placeProduct.Id); await redisCacheClient.Db0.SetRemoveAsync($"{configuration["db-prefix"]}{REDIS_KEY_PRODUCT_PLACES_BY_PP}_{placeProduct.PlaceProviderId}", placeProduct.Id); return(true); } catch (Exception exc) { logger.LogError(exc, exc.Message); throw; } }
public async Task <ActionResult <PlaceProduct> > InsertOrUpdatePlaceProduct( [FromBody] PlaceProduct placeProduct ) { try { if (!await User.IsPlaceProviderAdmin(userRepository, placeProviderRepository)) { throw new Exception(localizer[Controllers_PlaceController.Only_admin_is_allowed_to_manage_testing_places].Value); } var place = await placeRepository.GetPlace(placeProduct.PlaceId); if (place == null) { throw new Exception("Place not found"); } if (place.PlaceProviderId != User.GetPlaceProvider()) { throw new Exception("You can define product only for your places"); } var update = true; if (string.IsNullOrEmpty(placeProduct.Id)) { update = false; } logger.LogInformation($"InsertOrUpdatePlaceProduct : {placeProduct.PlaceId} {update}"); var products = await placeProviderRepository.ListProducts(User.GetPlaceProvider()); var product = products.FirstOrDefault(p => p.Id == placeProduct.ProductId); if (product == null) { throw new Exception("Product not found"); } if (!update) { // new place placeProduct.Id = Guid.NewGuid().ToString(); placeProduct.PlaceProviderId = User.GetPlaceProvider(); placeProduct.InsuranceOnly = product.InsuranceOnly; placeProduct.CollectInsurance = product.CollectInsurance; placeProduct.CollectEmployeeNo = product.CollectEmployeeNo; placeProduct.CollectNationality = product.CollectNationality; placeProduct.SchoolOnly = product.SchoolOnly; placeProduct.EmployeesOnly = product.EmployeesOnly; placeProduct.EHealthDefault = product.EHealthDefault; placeProduct.EmployeesRegistration = product.EmployeesRegistration; placeProduct = await placeRepository.SetProductPlace(placeProduct); logger.LogInformation($"ProductPlace {place.Name} has been created"); } else { // update existing if (placeProduct.PlaceProviderId != User.GetPlaceProvider()) { throw new Exception("You can define place products only for your places"); } var oldPlaceProduct = await placeRepository.GetPlaceProduct(placeProduct.Id); placeProduct.InsuranceOnly = product.InsuranceOnly; placeProduct = await placeRepository.SetProductPlace(placeProduct); logger.LogInformation($"Place {place.Name} has been updated"); } return(Ok(placeProduct)); } catch (ArgumentException exc) { logger.LogError(exc.Message); return(BadRequest(new ProblemDetails() { Detail = exc.Message })); } catch (Exception exc) { logger.LogError(exc, exc.Message); return(BadRequest(new ProblemDetails() { Detail = exc.Message })); } }
/// <summary> /// Set /// </summary> /// <param name="placeProduct"></param> /// <returns></returns> public override async Task <PlaceProduct> SetProductPlace(PlaceProduct placeProduct) { dataPlaceProduct[placeProduct.Id] = placeProduct; return(placeProduct); }
public async Task <ActionResult <Visitor> > Register([FromBody] Visitor visitor) { try { if (visitor is null) { throw new ArgumentNullException(nameof(visitor)); } if (!string.IsNullOrEmpty(configuration["googleReCaptcha:SiteKey"])) { if (string.IsNullOrEmpty(visitor.Token)) { throw new Exception("Please provide captcha"); } var validation = await captchaValidator.IsCaptchaPassedAsync(visitor.Token); if (!validation) { throw new Exception("Please provide valid captcha"); } visitor.Token = ""; } var time = new DateTimeOffset(visitor.ChosenSlot, TimeSpan.Zero); if (time.AddMinutes(10) < DateTimeOffset.Now) { throw new Exception("Na tento termín sa nedá zaregistrovať pretože časový úsek je už ukončený"); } if (string.IsNullOrEmpty(visitor.Address)) { visitor.Address = $"{visitor.Street} {visitor.StreetNo}, {visitor.ZIP} {visitor.City}"; } if (visitor.PersonType == "foreign") { if (string.IsNullOrEmpty(visitor.Passport)) { throw new Exception("Zadajte číslo cestovného dokladu prosím"); } } else { if (string.IsNullOrEmpty(visitor.RC)) { throw new Exception("Zadajte rodné číslo prosím"); } } if (string.IsNullOrEmpty(visitor.Street)) { throw new Exception("Zadajte ulicu trvalého bydliska prosím"); } if (string.IsNullOrEmpty(visitor.StreetNo)) { throw new Exception("Zadajte číslo domu trvalého bydliska prosím"); } if (string.IsNullOrEmpty(visitor.ZIP)) { throw new Exception("Zadajte PSČ trvalého bydliska prosím"); } if (string.IsNullOrEmpty(visitor.City)) { throw new Exception("Zadajte mesto trvalého bydliska prosím"); } if (string.IsNullOrEmpty(visitor.FirstName)) { throw new Exception("Zadajte svoje meno prosím"); } if (string.IsNullOrEmpty(visitor.LastName)) { throw new Exception("Zadajte svoje priezvisko prosím"); } if (!visitor.BirthDayYear.HasValue || visitor.BirthDayYear < 1900 || visitor.BirthDayYear > 2021) { throw new Exception("Rok Vášho narodenia vyzerá byť chybne vyplnený"); } if (!visitor.BirthDayDay.HasValue || visitor.BirthDayDay < 1 || visitor.BirthDayDay > 31) { throw new Exception("Deň Vášho narodenia vyzerá byť chybne vyplnený"); } if (!visitor.BirthDayMonth.HasValue || visitor.BirthDayMonth < 1 || visitor.BirthDayMonth > 12) { throw new Exception("Mesiac Vášho narodenia vyzerá byť chybne vyplnený"); } visitor.RegistrationTime = DateTimeOffset.UtcNow; visitor.SelfRegistration = true; var place = await placeRepository.GetPlace(visitor.ChosenPlaceId); if (place == null) { throw new Exception("Vybrané miesto nebolo nájdené"); } visitor.PlaceProviderId = place.PlaceProviderId; PlaceProduct placeProduct = null; try { placeProduct = await placeRepository.GetPlaceProduct(visitor.Product); } catch { } Product product = null; try { if (placeProduct == null) { product = await placeProviderRepository.GetProduct(place.PlaceProviderId, visitor.Product); } } catch { } if (product == null && placeProduct == null) { throw new Exception("Vybraná služba nebola nájdená"); } //logger.LogInformation($"EmployeesRegistration: {product.EmployeesRegistration}"); if (placeProduct?.EmployeesRegistration == true || product?.EmployeesRegistration == true) { logger.LogInformation($"EmployeesRegistration 2: {visitor.EmployeeId}"); if (string.IsNullOrEmpty(visitor.EmployeeId)) { throw new Exception("Zadajte prosím osobné číslo zamestnanca"); } var pp = await placeProviderRepository.GetPlaceProvider(place.PlaceProviderId); if (pp == null) { throw new Exception("Miesto má nastavené chybnú spoločnosť. Prosím kontaktujte podporu s chybou 0x021561"); } var hash = visitorRepository.MakeCompanyPeronalNumberHash(pp.CompanyId, visitor.EmployeeId); var regId = await visitorRepository.GetRegistrationIdFromHashedId(hash); var reg = await visitorRepository.GetRegistration(regId); logger.LogInformation($"EmployeesRegistration 3: {hash} {regId} {reg?.Id}"); if (reg == null) { throw new Exception("Zadajte prosím platné osobné číslo zamestnanca"); } var rc = reg.RC ?? ""; if (rc.Length > 4) { rc = rc.Substring(rc.Length - 4); } logger.LogInformation($"EmployeesRegistration 4: {rc}"); if (string.IsNullOrEmpty(visitor.RC) || !visitor.RC.EndsWith(rc)) { throw new Exception("Časť poskytnutého rodného čísla od zamestnávateľa vyzerá byť rozdielna od čísla zadaného v registračnom formulári"); } } return(Ok(await visitorRepository.Register(visitor, "", true))); } catch (ArgumentException exc) { logger.LogError(exc.Message); return(BadRequest(new ProblemDetails() { Detail = exc.Message })); } catch (Exception exc) { logger.LogError(exc, exc.Message); return(BadRequest(new ProblemDetails() { Detail = exc.Message })); } }