public bool CreateAccount(Account account)
        {
            bool exist = false;

            Account acc = context.Accounts.FirstOrDefault(x => x.Username.Equals(account.Username));
            if (acc==null)
            {
                exist = true;
                context.Accounts.Add(account);
            }
            context.SaveChanges();
            return exist;
        }
 public void SaveAccount(Account account)
 {
     Account dbEntry = context.Accounts.Find(account.AccountId);
     if (dbEntry != null)
     {
         dbEntry.Name = account.Name;
         dbEntry.Address = account.Address;
         if (account.ImageData != null)
         {
             dbEntry.ImageData = account.ImageData;
             dbEntry.ImageMimeType = account.ImageMimeType;
         }
     }
     context.SaveChanges();
 }
 private void CheckUploadImage(Account account,HttpPostedFileBase image)
 {
     if (image != null)
     {
         account.ImageMimeType = image.ContentType;
         account.ImageData = new byte[image.ContentLength];
         image.InputStream.Read(account.ImageData, 0, image.ContentLength);
     }
 }
 public ActionResult Update(Account account,HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         CheckUploadImage(account, image);
         repository.SaveAccount(account);
         TempData["message"] = string.Format("{0} has been updated", account.Username);
         return RedirectToAction("List", "Product");
     }
     else
     {
         return View("Profile",account);
     }
 }
 public ActionResult Register(Account account,HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         if (account.Username.ToLower() != "admin")
         {
             CheckUploadImage(account, image);
             bool succeed = repository.CreateAccount(account);
             if (succeed)
             {
                 TempData["message"] = string.Format("{0} has been saved", account.Username);
                 return RedirectToAction("Login", "Account");
             }
             else
             {
                 ModelState.AddModelError("", "The username already exists!");
                 return View();
             }
         }else{
             ModelState.AddModelError("", "The username already exists!");
             return View();
         }
     }
     else
     {
         return View();
     }
 }