Beispiel #1
0
 public void DeleteSiteUser(string userId, HttpServerUtilityBase server)
 {
     try
     {
         SiteUserClaim siteUserClaim = db.SiteUserClaims.Where(suc => suc.SiteUserId == userId && suc.ClaimType.Type == "Picture").First();
         System.IO.File.Delete(server.MapPath("~/Images/Uploaded/Source/" + siteUserClaim.ClaimValue));
         db.SiteUserClaims.Remove(siteUserClaim);
     }
     catch (Exception) { }
     try
     {
         SiteUser siteUser = db.SiteUsers.Include("ApplicationUser").Where(su => su.Id == userId).First();
         db.SiteUserClaims.RemoveRange(db.SiteUserClaims.Where(suc => suc.SiteUserId == userId));
         db.SiteUserKindergartens.RemoveRange(db.SiteUserKindergartens.Where(suk => suk.SiteUserId == userId));
         List <Rating> userRatings = db.Ratings.Where(r => r.SiteUserId == userId).ToList();
         for (int i = 0; i < userRatings.Count; i++)
         {
             for (int j = 0; j < userRatings[i].QuestionRatings.Count; j++)
             {
                 db.QuestionRatings.Remove(userRatings[i].QuestionRatings.ToList()[j]);
             }
         }
         db.Ratings.RemoveRange(userRatings);
         if (siteUser != null)
         {
             db.Users.Remove(siteUser.ApplicationUser);
             db.SiteUsers.Remove(siteUser);
             db.SaveChanges();
         }
     }
     catch (Exception) { }
 }
Beispiel #2
0
        public void EditSiteUser(EditUserViewModel model, string userId, HttpServerUtilityBase server)
        {
            SiteUser siteUser = db.SiteUsers.Where(su => su.Id == userId).First();

            siteUser.Name                        = model.Name;
            siteUser.Surname                     = model.Surname;
            siteUser.FathersName                 = model.FathersName;
            siteUser.ApplicationUser.Email       = model.Email;
            siteUser.ApplicationUser.PhoneNumber = "+38 " + model.PhoneNumber;
            if (model.PictureName != null)
            {
                SiteUserClaim siteUserClaim;
                try
                {
                    siteUserClaim = db.SiteUserClaims.Where(suc => suc.SiteUserId == userId && suc.ClaimType.Type == "Picture").First();
                    string previosClaimValue = siteUserClaim.ClaimValue;
                    siteUserClaim.ClaimValue = model.PictureName;
                    System.IO.File.Copy(server.MapPath("~/Images/Uploaded/Temp/" + model.PictureName), server.MapPath("~/Images/Uploaded/Source/" + model.PictureName));
                    System.IO.File.Delete(server.MapPath("~/Images/Uploaded/Temp/" + model.PictureName));
                    System.IO.File.Delete(server.MapPath("~/Images/Uploaded/Source/" + previosClaimValue));
                }
                catch (Exception)
                {
                    AddPictureClaim(siteUser.Id, model.PictureName, server);
                }
            }
            else
            {
                try
                {
                    SiteUserClaim siteUserClaim = db.SiteUserClaims.Where(suc => suc.SiteUserId == userId && suc.ClaimType.Type == "Picture").First();
                    System.IO.File.Delete(server.MapPath("~/Images/Uploaded/Source/" + siteUserClaim.ClaimValue));
                    db.SiteUserClaims.Remove(siteUserClaim);
                }
                catch (Exception) { }
            }
            siteUser.DateOfBirth = model.DateOfBirth;
            db.SaveChanges();
        }