Esempio n. 1
0
 private static bool ExecuteDB(UserProfile usrprof, DBQueryType queryType)
 {
     using (spiffaiwebEntities db = LoadDB())
     {
         switch (queryType)
         {
             case DBQueryType.Add:
                 db.UserProfiles.Add(usrprof);
                 break;
             case DBQueryType.Update:
                 db.UserProfiles.Attach(usrprof);
                 db.Entry(usrprof).State = System.Data.Entity.EntityState.Modified;
                 break;
             case DBQueryType.Delete:
                 db.UserProfiles.Remove(usrprof);
                 break;
             default:
                 break;
         }
         db.SaveChanges();
     }
     return true;
 }
Esempio n. 2
0
 public static bool Add(UserProfile usrprof)
 {
     return ExecuteDB(usrprof, DBQueryType.Add);
 }
Esempio n. 3
0
 public static bool Delete(UserProfile usrprof)
 {
     return ExecuteDB(usrprof, DBQueryType.Delete);
 }
        public ActionResult UploadAvatar(UserProfile profile)
        {
            HttpPostedFileBase hpf = Request.Files["NewAvatar"];
            if (hpf != null && hpf.ContentLength > 0)
            {
                //validate file extension
                var fileName = hpf.FileName;
                if (ValidateLogoExtension(fileName))
                {
                    //UpdateAvatar
                    var userProfile = profile;
                    //userProfile.UserId = DAL.GetUserId(User.Identity.Name);

                    using (var binaryReader = new BinaryReader(hpf.InputStream))
                    {
                        userProfile.Avatar = binaryReader.ReadBytes(hpf.ContentLength);
                    }
                    db.Entry(userProfile).State = EntityState.Modified;
                    db.SaveChanges();

                    return RedirectToAction("ProfileChangeSuccess");
                }
            }
            return RedirectToAction("ProfileChangeFailed");
        }