public void UpdateUserProfile([FromBody] User user) { if (user == null || user.Id != GetUserAccess().UserId) { throw new ForbiddenException("Sie können nur Ihren eigenen Benutzer bearbeiten."); } CheckCustomAttributes.CheckRequiredAttribute(user); var originalUser = userDataAccess.GetUser(user.Id); CheckCustomAttributes.CheckEditNotAllowedAttribute(originalUser, user); CheckCustomAttributes.CheckEditNotAllowedForAttribute(originalUser, user); userDataAccess.UpdateUserProfile(ControllerHelper.GetCurrentUserId(), user); }
public HttpResponseMessage UpdateUser([FromBody] UserPostData postData) { var access = this.GetManagementAccess(); if (string.IsNullOrEmpty(postData?.Id)) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } // Logic validieren if (postData.ResearcherGroup && postData.BarInternalConsultation) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (postData.ResearcherGroup && (postData.RolePublicClient == null || !postData.RolePublicClient.Equals(AccessRoles.RoleOe3))) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } // Pflichtfelder validieren if (string.IsNullOrEmpty(postData.FamilyName)) { throw new BadRequestException("Name muss angegeben werden."); } if (string.IsNullOrEmpty(postData.FirstName)) { throw new BadRequestException("Vorname muss angegeben werden."); } if (string.IsNullOrEmpty(postData.Street)) { throw new BadRequestException("Strasse muss angegeben werden."); } if (string.IsNullOrEmpty(postData.ZipCode)) { throw new BadRequestException("PLZ muss angegeben werden."); } if (string.IsNullOrEmpty(postData.Town)) { throw new BadRequestException("Ort muss angegeben werden."); } if (string.IsNullOrEmpty(postData.CountryCode)) { throw new BadRequestException("Land muss angegeben werden."); } if (string.IsNullOrEmpty(postData.EmailAddress)) { throw new BadRequestException("E-Mail muss angegeben werden."); } if (!string.IsNullOrEmpty(postData.BirthdayString)) { if (DateTime.TryParse(postData.BirthdayString, CultureInfo.GetCultureInfo("de-DE"), DateTimeStyles.None, out var birthday)) { postData.Birthday = birthday; } else { throw new BadRequestException("The property BirthdayString is not in the expected format dd.mm.yyyy."); } } if (!string.IsNullOrEmpty(postData.DownloadLimitDisabledUntilString)) { if (DateTime.TryParse(postData.DownloadLimitDisabledUntilString, CultureInfo.GetCultureInfo("de-DE"), DateTimeStyles.None, out var downloadLimitDisabledUntil)) { postData.DownloadLimitDisabledUntil = downloadLimitDisabledUntil; } else { throw new BadRequestException("The property DownloadLimitDisabledUntilString is not in the expected format dd.mm.yyyy."); } } if (!string.IsNullOrEmpty(postData.DigitalisierungsbeschraenkungString)) { if (DateTime.TryParse(postData.DigitalisierungsbeschraenkungString, CultureInfo.GetCultureInfo("de-DE"), DateTimeStyles.None, out var digitalisierungsbeschraenkungAufgehobenBis)) { postData.DigitalisierungsbeschraenkungAufgehobenBis = digitalisierungsbeschraenkungAufgehobenBis; } else { throw new BadRequestException("The property DigitalisierungsbeschraenkungString is not in the expected format dd.mm.yyyy."); } } var originalUser = userDataAccess.GetUser(postData.Id); CheckCustomAttributes.CheckEditNotAllowedAttribute(originalUser, postData); CheckCustomAttributes.CheckEditNotAllowedForAttribute(originalUser, postData); CheckCustomAttributes.CheckEditRequiresFeatureAttribute(GetUser().Features, originalUser, postData); userDataAccess.UpdateUser(postData, access.UserId); // Alle zugewiesen Abliefernde Stellen löschen if (postData.RolePublicClient != AccessRoles.RoleAS) { userDataAccess.DeleteAllAblieferdeStelleFromUser(postData.Id); } var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new JsonContent(new JObject { { "success", true } }) }; return(response); }