Ejemplo n.º 1
0
        public async Task <ExSaveDataResult> DeleteUserWeb([FromBody] ExDeleteRequest request)
        {
            if (request.CheckPassword != WebAppSettings.CheckPassword)
            {
                HttpContext.Response.StatusCode = Unauthorized().StatusCode;
                return(null);
            }

            return(await DeleteUsereInternal(request.Id));
        }
Ejemplo n.º 2
0
        public async Task <ExSaveDataResult> DeleteUser([FromBody] ExDeleteRequest request)
        {
            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 userClaimId = identity.HasClaim(c => c.Type == "UserID")
                    ? identity.FindFirst("UserID").Value
                    : "a"; //BENUTZER ID

                if (request.Id.ToString() != userClaimId)
                {
                    HttpContext.Response.StatusCode = Unauthorized().StatusCode;
                    return(null);
                }
            }
            else
            {
                HttpContext.Response.StatusCode = Unauthorized().StatusCode;
                return(null);
            }

            return(await DeleteUsereInternal(request.Id));
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Shop löschen
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public async Task <ResultData <bool> > DeleteShop(ExDeleteRequest request)
 {
     return(await _wap.Post <bool>("DeleteShop", request));
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Userdaten löschen für WebApp
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public async Task <ResultData <ExSaveDataResult> > DeleteUserWeb(ExDeleteRequest request)
 {
     return(await _wap.Post <ExSaveDataResult>("DeleteUserWeb", request));
 }
Ejemplo n.º 5
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);
        }