Esempio n. 1
0
        /// <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());
                }
            }
        }
Esempio n. 2
0
        public async Task <bool> DeleteShop([FromBody] ExDeleteRequest request)
        {
            var shopId = request.Id;

            if (request.CheckPassword != WebAppSettings.CheckPassword)
            {
                HttpContext.Response.StatusCode = Unauthorized().StatusCode;
                return(false);
            }

            using (var db = new Db())
            {
                //Kundentermine absagen
                var appointments = db.TblAppointments
                                   .Include(x => x.Employee)
                                   .Where(a => a.Employee.StoreId == shopId);
                var appointmentsToInformForDelete = appointments.Where(a => a.ValidFrom > DateTime.UtcNow && a.Canceled == false);
                var mc = new MeetingController(_view);
                foreach (var appointment in appointmentsToInformForDelete)
                {
                    await mc.DeleteMeetingWeb(new ExRemoveMeetingRequest
                    {
                        UserType      = EnumUserType.ShopEmployee,
                        MeetingId     = appointment.Id,
                        CheckPassword = WebAppSettings.CheckPassword,
                        UserId        = -1
                    });
                }

                //Kundentermine löschen
                db.TblAppointments.RemoveRange(appointments);

                //Mitarbeiter löschen
                var emp = db.TblEmployees
                          .Include(x => x.TblLocationEmployee).Where(e => e.StoreId == shopId);
                foreach (var e in emp)
                {
                    db.TblLocationEmployee.RemoveRange(e.TblLocationEmployee);
                }

                db.TblEmployees.RemoveRange(emp);

                //Shop
                var shop = await db.TblStores.Include(i => i.TblLocations).Include(i => i.TblStoreDelivery).Include(i => i.TblStorePayments).Include(i => i.TblStoreCategories).FirstOrDefaultAsync(s => s.Id == shopId);

                if (shop == null)
                {
                    return(false);
                }

                //Zwischentabellen
                db.TblLocations.RemoveRange(shop.TblLocations);
                db.TblStoreDelivery.RemoveRange(shop.TblStoreDelivery);
                db.TblStorePayment.RemoveRange(shop.TblStorePayments);
                db.TblStoreCategory.RemoveRange(shop.TblStoreCategories);


                //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 emailContent = $"Leider hat der Shop {shop.CompanyName} mit der Telefonnummer {shop.Telephonenumber} 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.TblStores.Remove(shop);

                try
                {
                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    Logging.Log.LogError($"Error deleting Shop: {shop.CompanyName} Id: {shopId}: {e}");
                    return(false);
                }
            }

            return(true);
        }