public async Task <ExSaveDataResult> ClearUserDevices() { using (var db = new Db()) { var data = await db.TblUserDevices.ToListAsync(); db.TblUserDevices.RemoveRange(data); try { var service = new MobileCenterNotification(Constants.MobileCenterNotification); if (data.Any()) { foreach (var userDevice in data) { await service.RemoveDevice(userDevice.Device.DeviceToken, userDevice.Device.Plattform); } } db.SaveChanges(); } catch (Exception e) { Logging.Log.LogWarning($"UserDeviceDelete SaveChanges: {e}"); return(ExSaveDataResult.GetDefaultSaveError()); } return(ExSaveDataResult.GetDefaultSuccess()); } }
public async Task <ExSaveDataResult> NotificationTestAudience() { Logging.Log.LogInfo("NotificationTestAudience"); var service = new MobileCenterNotification(Constants.MobileCenterNotification); Task.Run(async() => await service.GetAudience(EnumPlattform.XamarinAndroid, "Testgruppe")); return(ExSaveDataResult.GetDefaultSuccess()); }
/// <summary> /// Termin entfernen /// </summary> /// <param name="request"></param> /// <returns></returns> private async Task <ExSaveDataResult> DeleteMeetingInternal([FromBody] ExRemoveMeetingRequest request) { using (var db = new Db()) { var meeting = db.TblAppointments .Include(x => x.Employee) .Include(x => x.Employee).ThenInclude(x => x.Store) .Include(x => x.User) .FirstOrDefault(x => x.Id == request.MeetingId); if (meeting.UserId != request.UserId && request.UserType == EnumUserType.Customer) { return(new ExSaveDataResult { Result = EnumSaveDataResult.Error, Caption = "Nicht möglich!", Description = "Nur der Ersteller des Termins kann diesen auch wieder löschen!" }); } meeting.Canceled = true; try { switch (request.UserType) { //Kunde hat den Termin storniert => E-Mail an Shop als Info case EnumUserType.Customer: string shopEMail = meeting.Employee.Store.EMail; string userName = $"{meeting.User.Firstname} {meeting.User.Lastname}"; string emailContent = $"Leider hat {(String.IsNullOrEmpty(userName.Trim()) ? "UNBEKANNT" : userName)} den Termin am {meeting.ValidFrom.AddHours(2):dd.MM.yyy} um {meeting.ValidFrom.AddHours(2):HH:mm} absagen müssen."; string employeeTel = meeting.Employee.TelephoneNumber; string email = _mailgenerator.GetStornoAppointmentShopEmail(new ExEMailStornoAppointmentShop { Message = emailContent }); BissEMail bm = new BissEMail(WebAppSettings.EmailCredentials); var res = await bm.SendHtmlEMail(Constants.SendEMailAs, new List <string> { shopEMail }, "Termin-Storno", email, Constants.SendEMailAsDisplayName); //ToDo: Umstellung auf Push sobald möglich //Common.SendSMS(employeeTel, $"{emailContent} Auf diese SMS kann nicht geantwortet werden."); break; //Shop musst den Termin stonieren => SMS an Kunden als Info //ToDo: Umstellung auf Push sobald möglich case EnumUserType.ShopEmployee: string telCustomer = meeting.User.PhoneNumber; string employeeName = $"{meeting.Employee.FirstName} {meeting.Employee.LastName}"; string smsContent = $"Leider hat {(String.IsNullOrEmpty(employeeName.Trim()) ? "UNBEKANNT" : employeeName)} von {meeting.Employee.Store.CompanyName} den Termin am {meeting.ValidFrom.AddHours(2):dd.MM.yyy} um {meeting.ValidFrom.AddHours(2):HH:mm} absagen müssen. Du kannst gerne wieder einen neuen Termin über die App vereinbaren. Auf diese SMS kann nicht geantwortet werden."; Common.SendSMS(telCustomer, smsContent); break; default: throw new ArgumentOutOfRangeException(); } } catch (Exception e) { Logging.Log.LogWarning($"Could not inform customer or shop about chanceled appointment: {e}"); } try { await db.SaveChangesAsync(); return(ExSaveDataResult.GetDefaultSuccess()); } catch (Exception e) { Logging.Log.LogError($"{e}"); return(ExSaveDataResult.GetDefaultSaveError()); } } }
/// <summary> /// Termin vereinbaren /// </summary> /// <param name="request"></param> /// <returns></returns> private async Task <ExSaveDataResult <ExMeeting> > SetMeetingInternal([FromBody] ExSaveMeetingRequest request) { using (var db = new Db()) { var freeEmployeeId = request.StaffId; if (freeEmployeeId == null) { var employees = db.TblLocations .Include(x => x.TblLocationEmployee) .Include(x => x.TblLocationEmployee).ThenInclude(x => x.TblEmployee) .AsNoTracking() .FirstOrDefault(x => x.Id == request.LocationId)?.TblLocationEmployee; // TODO Freien Mitarbeiter suchen var employeesFree = employees?.Where(x => x.TblEmployee.Active); freeEmployeeId = employeesFree?.FirstOrDefault()?.Id; } if (freeEmployeeId == null) { return(new ExSaveDataResult <ExMeeting> { Description = "Leider wurde kein freier Verkäufer gefunden!", Caption = "Kein freier Termin", Result = EnumSaveDataResult.Error, Data = null, }); } // prüfen ob der Mitarbeiter (noch) Zeit hat var locationEmployee = db.TblEmployees .Include(x => x.TblVirtualWorkTimes) .AsNoTracking() .FirstOrDefault(x => x.Id == freeEmployeeId.Value); var slotTime = locationEmployee.TblVirtualWorkTimes.FirstOrDefault(x => x.Weekday == request.StartTime.Date.DayOfWeek); if (slotTime == null) { return(new ExSaveDataResult <ExMeeting> { Description = "Leider hat der Verkäufer heute frei.", Caption = "Kein Arbeitstag", Result = EnumSaveDataResult.Error, Data = null, }); } var meeting = db.TblAppointments.AsNoTracking() .FirstOrDefault(x => x.EmployeeId == locationEmployee.Id && x.ValidTo > request.StartTime && x.ValidFrom <= request.StartTime && !x.Canceled); if (meeting != null) { return(new ExSaveDataResult <ExMeeting> { Description = "Der gewünschte Verkäufer hat zu diesem Zeitpunkt leider bereits einen Termin.", Caption = "Terminkonflikt", Result = EnumSaveDataResult.Error, Data = null, }); } var dbMeeting = new TableAppointment { UserId = request.UserId, EmployeeId = freeEmployeeId.Value, Text = request.OptionalText, BookedOn = DateTime.UtcNow, ValidFrom = request.StartTime, ValidTo = request.StartTime.AddMinutes(slotTime?.TimeSlot ?? 1), Attended = false, Canceled = false, AppointmentDate = request.StartTime.Date, }; db.TblAppointments.Add(dbMeeting); try { await db.SaveChangesAsync(); } catch (Exception e) { Logging.Log.LogError($"{e}"); return(new ExSaveDataResult <ExMeeting> { Description = ExSaveDataResult.GetDefaultSaveError().Description, Caption = ExSaveDataResult.GetDefaultSaveError().Caption, Result = EnumSaveDataResult.Error, Data = null, }); } var shop = db.TblLocations .Include(x => x.Store) .AsNoTracking() .FirstOrDefault(x => x.Id == request.LocationId); var res = new ExSaveDataResult <ExMeeting> { Result = EnumSaveDataResult.Ok, Caption = ExSaveDataResult.GetDefaultSuccess().Caption, Description = ExSaveDataResult.GetDefaultSuccess().Description, Data = new ExMeeting { Id = dbMeeting.Id, Start = dbMeeting.ValidFrom, End = dbMeeting.ValidTo, ShopId = shop.Id, ShopName = shop.Store.CompanyName, Staff = Staff.GetExStaff(db, dbMeeting.EmployeeId), UserId = dbMeeting.UserId, } }; //Shop per E-Mail über neuen Termin informieren try { var meetingInfo = db.TblAppointments .Include(x => x.Employee) .Include(x => x.Employee).ThenInclude(x => x.Store) .Include(x => x.User) .FirstOrDefault(x => x.Id == dbMeeting.Id); string shopEMail = meetingInfo.Employee.Store.EMail; string userName = $"{meetingInfo.User.Firstname} {meetingInfo.User.Lastname}"; string emailContent = $"Neuer Termin mit {(String.IsNullOrEmpty(userName.Trim()) ? "UNBEKANNT" : userName)} am {meetingInfo.ValidFrom.AddHours(2):dd.MM.yyy} um {meetingInfo.ValidFrom.AddHours(2):HH:mm}."; string email = _mailgenerator.GetMessageOnlyEmail(new ExEMailMessageOnly { Message = emailContent }); BissEMail bm = new BissEMail(WebAppSettings.EmailCredentials); await bm.SendHtmlEMail(Constants.SendEMailAs, new List <string> { shopEMail }, "Neuer Termin", email, Constants.SendEMailAsDisplayName); } catch (Exception e) { Logging.Log.LogWarning($"E-Mail über neuen Termin konnte nicht gesendet werden: {e}"); throw; } return(res); } }
/// <summary> /// Userdaten löschen /// </summary> /// <param name="userId"></param> /// <returns></returns> private async Task <ExSaveDataResult> DeleteUsereInternal(int userId) { using (var db = new Db()) { var user = db.TblUsers.Include(i => i.TblAppointments).Include(i => i.TblUserDevices).FirstOrDefault(x => x.Id == userId); if (user.IsAdmin || user.IsDemoUser) { return(new ExSaveDataResult { Description = "Admins oder Demouser können nicht gelöscht werden!", Caption = "Nicht möglich!", Result = EnumSaveDataResult.Information, }); } //Termine absagen und löschen var mc = new MeetingController(_view); var appointmentsToInform = user.TblAppointments.Where(a => a.ValidFrom > DateTime.UtcNow && a.Canceled == false); foreach (var appointment in appointmentsToInform) { await mc.DeleteMeetingWeb(new ExRemoveMeetingRequest { UserType = EnumUserType.Customer, MeetingId = appointment.Id, UserId = userId, CheckPassword = WebAppSettings.CheckPassword, }); } db.TblAppointments.RemoveRange(user.TblAppointments); db.TblUserDevices.RemoveRange(user.TblUserDevices); //ToDo: Geräte auch aus AzurePush entfernen! //Admins informieren List <string> eMails2Inform; if (Constants.CurrentAppSettings.AppConfigurationConstants == 0) //master { eMails2Inform = new List <string> { "*****@*****.**", "*****@*****.**", }; //ToDo: Wenn die Settings Tabelle existiert dann über die Settings Tabelle } else { eMails2Inform = new List <string> { "*****@*****.**" }; //ToDo: Wenn die Settings Tabelle existiert dann über die Settings Tabelle } string userName = $"{user.Firstname} {user.Lastname}"; string emailContent = $"Leider hat {(String.IsNullOrEmpty(userName.Trim()) ? "UNBEKANNT" : userName)} mit der Telefonnummer {user.PhoneNumber} seinen Account gelöscht."; string email = _mailgenerator.GetMessageOnlyEmail(new ExEMailMessageOnly { Message = emailContent }); BissEMail bm = new BissEMail(WebAppSettings.EmailCredentials); var res = await bm.SendHtmlEMail(Constants.SendEMailAs, eMails2Inform, "Kunde gelöscht.", email, Constants.SendEMailAsDisplayName); //Löschen db.TblUsers.Remove(user); try { await db.SaveChangesAsync(); return(ExSaveDataResult.GetDefaultSuccess()); } catch (Exception e) { Logging.Log.LogError($"{e}"); return(ExSaveDataResult.GetDefaultSaveError()); } } }
public async Task <ExSaveDataResult> UserUpdate([FromBody] ExUserAccountData user) { ClaimsIdentity identity = null; try { identity = HttpContext.User.Identity as ClaimsIdentity; } catch (Exception e) { Logging.Log.LogError("No Claims identity"); } if (identity != null) { var claims = identity.Claims; if (!identity.HasClaim(c => c.Type == "UserID")) { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(null); } var userId = identity.HasClaim(c => c.Type == "UserID") ? identity.FindFirst("UserID").Value : "a"; //BENUTZER ID if (user.UserId.ToString() != userId) { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(null); } } else { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(null); } Logging.Log.LogInfo($"UserUpdate {user.UserId}"); using (var db = new Db()) { if (user.IsDemoUser) { return new ExSaveDataResult { Result = EnumSaveDataResult.Information, Description = "Daten können nicht geändert werden.", Caption = "Nicht möglich" } } ; var data = await db.TblUsers.FirstOrDefaultAsync(u => u.Id == user.UserId); if (data == null) { return new ExSaveDataResult { Result = EnumSaveDataResult.Error, Description = "Account ungültig!", Caption = "Fehler" } } ; data.Firstname = user.FirstName; data.Lastname = user.LastName; data.Street = user.Street; data.PostalCode = user.PostalCode; data.City = user.City; try { db.SaveChanges(); } catch (Exception e) { Logging.Log.LogWarning($"UserDeviceUpdate Save: {e}"); return(ExSaveDataResult.GetDefaultSaveError()); } return(ExSaveDataResult.GetDefaultSuccess()); } }
public async Task <ExSaveDataResult> UserUpdatePassword([FromBody] ExPostUserChangePasswortData password) { ClaimsIdentity identity = null; try { identity = HttpContext.User.Identity as ClaimsIdentity; } catch (Exception e) { Logging.Log.LogError("No Claims identity"); } if (identity != null) { var claims = identity.Claims; if (!identity.HasClaim(c => c.Type == "UserID")) { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(null); } var userId = identity.HasClaim(c => c.Type == "UserID") ? identity.FindFirst("UserID").Value : "a"; //BENUTZER ID if (password.UserId.ToString() != userId) { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(null); } } else { HttpContext.Response.StatusCode = Unauthorized().StatusCode; return(null); } Logging.Log.LogInfo($"UserUpdatePassword {password.UserId}"); using (var db = new Db()) { var data = await db.TblUsers.FirstOrDefaultAsync(u => u.Id == password.UserId); if (data == null) { return new ExSaveDataResult { Result = EnumSaveDataResult.Error, Description = "Account ungültig!", Caption = "Fehler" } } ; if (data.Password != password.OldPasswordHash) { return new ExSaveDataResult { Result = EnumSaveDataResult.Warning, Description = "Aktuelles Passwort falsch!", Caption = "Nicht möglich" } } ; data.Password = password.NewPasswordHash; try { db.SaveChanges(); } catch (Exception e) { Logging.Log.LogWarning($"UserDeviceUpdate Save: {e}"); return(ExSaveDataResult.GetDefaultSaveError()); } return(ExSaveDataResult.GetDefaultSuccess()); } }