public async Task <ActionResult> AddStaffAccount(string values)
        {
            AdminUser userAdmin = new AdminUser();

            JsonConvert.PopulateObject(values, userAdmin);
            var user = new ApplicationUser {
                UserName = userAdmin.UserName, Email = userAdmin.UserName
            };
            var result = await UserManager.CreateAsync(user, userAdmin.Password);

            if (result.Succeeded)
            {
                ApplicationUser currentUser = _dbasp.Users.FirstOrDefault(x => x.Email.Equals(userAdmin.UserName));
                await UserManager.AddToRoleAsync(currentUser.Id, ConvertAccsessToRole(userAdmin.Acess.Value));

                currentUser.EmailConfirmed = true;
                userAdmin.ID_AdminUser     = currentUser.Id;
                _db.Entry(userAdmin).State = System.Data.Entity.EntityState.Added;
                _db.SaveChanges();
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
Пример #2
0
        public void ProcessChangeAvatar(HttpPostedFileBase ChangeAvatarImage)
        {
            try
            {
                string[] imageExtensions   = { ".jpg", ".jpeg", ".gif", ".png" };
                var      fileName          = ChangeAvatarImage.FileName.ToLower();
                var      isValidExtenstion = imageExtensions.Any(ext =>
                {
                    return(fileName.LastIndexOf(ext) > -1);
                });

                if (isValidExtenstion)
                {
                    // Uncomment to save the file
                    //var path = Server.MapPath("~/Content/ImageUploaded/ImageForUser/");
                    string path = Path.Combine(Server.MapPath("~/Content/ImageUploaded/ImageForUser/"), Path.GetFileName(ChangeAvatarImage.FileName));
                    //if (!Directory.Exists(path))
                    //    Directory.CreateDirectory(path);

                    if (SaveResizeImage(Image.FromStream(ChangeAvatarImage.InputStream), path))
                    {
                        var tempForChange = _dbBCDH.Accounts.AsNoTracking().SingleOrDefault(x => x.Username == User.Identity.Name);
                        tempForChange.Img = fileName;
                        _dbBCDH.Entry(tempForChange).State = System.Data.Entity.EntityState.Modified;
                        _dbBCDH.SaveChanges();
                    }

                    //Test.SaveAs(path);
                }
            }
            catch
            {
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
        }
Пример #3
0
        public async Task <JsonResult> UpdatePasswordPrivate(string NewPassword)
        {
            var UserTemp = UserManager.FindById(User.Identity.GetUserId());

            if (await ChangePassword(NewPassword, UserTemp.Id))
            {
                var UserTempAdminAccount = _db.AdminUsers.Where(x => x.ID_AdminUser == UserTemp.Id).SingleOrDefault();
                UserTempAdminAccount.Password         = NewPassword;
                _db.Entry(UserTempAdminAccount).State = System.Data.Entity.EntityState.Modified;
                return(_db.SaveChanges() > 0? Json(new { Result = true }):Json(new { Result = false }));
            }
            return(Json(new { Result = false }));
        }
        public ActionResult AddImageProduct(string key, string values)
        {
            ImageForProduct temp = new ImageForProduct();

            JsonConvert.PopulateObject(values, temp);
            _db.Entry(temp).State = System.Data.Entity.EntityState.Added;
            var rs = _db.SaveChanges();

            if (rs > 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
      public ActionResult DeleteCategory(string key)
      {
          var TempCategory = _db.Categories.Select(x => x).Where(x => x.ID_Category == key).SingleOrDefault();

          if (TempCategory != null)
          {
              _db.Entry(TempCategory).State = System.Data.Entity.EntityState.Deleted;
              _db.SaveChanges();
              return(new HttpStatusCodeResult(HttpStatusCode.OK));
          }
          else
          {
              return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
          }
      }
Пример #6
0
        public async Task <JsonResult> AddWishList(string productID)
        {
            if (productID != null || productID != "")
            {
                var userTemp = await UserManager.FindByEmailAsync(User.Identity.Name);

                if (userTemp != null)
                {
                    var productExsit = _dbBCDHX.WishLists.AsNoTracking().Where(x => x.ID_Account == userTemp.Id && x.ID_Product == productID).SingleOrDefault();
                    if (productExsit != null)
                    {
                        return(Json(new { Error = "Sản phẩm đã tồn tại trong wishList", Status = 3 }));
                    }
                    else
                    {
                        var productTemp = _dbBCDHX.Products.AsNoTracking().Where(x => x.ID_Product == productID).SingleOrDefault();
                        if (productTemp != null)
                        {
                            var      wishListID    = _randomcode.RandomNumber(4);
                            WishList wishListmodel = new WishList {
                                ID_Account = userTemp.Id, ID_Product = productID, ID_WishList = wishListID
                            };
                            _dbBCDHX.Entry(wishListmodel).State = System.Data.Entity.EntityState.Added;
                            _dbBCDHX.SaveChanges();
                            return(Json(new { Error = "Thêm sản phẩm thành công vào wishList", Status = 1 }));
                        }
                        else
                        {
                            return(Json(new { Error = "Lỗi sảy ra", Status = 2 }));
                        }
                    }
                }
                else
                {
                    return(Json(new { Error = "Bạn phải đăng nhập mới thêm sản phẩm vào wishList của mình được!", Status = 4 }));
                }
            }
            else
            {
                return(Json(new { Error = "Lỗi sảy ra", Status = 2 }));
            }
        }
 public ActionResult EditPageBanner(string values, string key)
 {
     if (key != null)
     {
         var    id   = Convert.ToInt32(key);
         Silder temp = _db.Silders.AsNoTracking().Where(x => x.SliderID == id).SingleOrDefault();
         JsonConvert.PopulateObject(values, temp);
         _db.Entry(temp).State = System.Data.Entity.EntityState.Modified;
         var rs = _db.SaveChanges();
         if (rs > 0)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.OK));
         }
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     else
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
Пример #8
0
        public ActionResult EditPageOrder(string key, string values)
        {
            var tempOrder = _db.Invoices.AsNoTracking().Where(x => x.ID_Invoice == key).SingleOrDefault();

            if (tempOrder != null)
            {
                JsonConvert.PopulateObject(values, tempOrder);
                _db.Entry(tempOrder).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
Пример #9
0
 public async Task <JsonResult> UpdateGeneralProfile([Bind(Exclude = "ID_Account,Amount,Username")] Account account)
 {
     using (_dbBCDH)
     {
         var UserTemp = UserManager.FindById(User.Identity.GetUserId());
         if (await ChangePassword(account.Password, UserTemp.Id))
         {
             var ChangeAccount = _dbBCDH.Accounts.AsNoTracking().SingleOrDefault(x => x.ID_Account == IDUser);
             account.ID_Account           = IDUser;
             account.Username             = ChangeAccount.Username;
             account.Amount               = ChangeAccount.Amount;
             account.Access               = ChangeAccount.Access;
             account.Img                  = ChangeAccount.Img;
             _dbBCDH.Entry(account).State = System.Data.Entity.EntityState.Modified;
             var rs = _dbBCDH.SaveChanges();
             if (rs == 1)
             {
                 return(Json(new
                 {
                     Status = 0,
                     Error = "Cập nhật thành công"
                 }));
             }
             else
             {
                 return(Json(new
                 {
                     Status = 1,
                     Error = "Cập nhật không thành công"
                 }));
             }
         }
         else
         {
             return(Json(new
             {
                 Status = 1,
                 Error = "Cập nhật không thành công"
             }));
         }
     }
 }
Пример #10
0
        public ActionResult WebHookResult(HttpContext context)
        {
            var jsonSerialzer = new JavaScriptSerializer();
            var jsonString    = string.Empty;

            context.Request.InputStream.Position = 0;
            using (var inputStream = new StreamReader(context.Request.InputStream))
            {
                jsonString = inputStream.ReadToEnd();
            }
            var data = new PaymentWebWook();

            data = jsonSerialzer.Deserialize <PaymentWebWook>(jsonString);
            var        number_ramdom = new RandomCode().RandomNumber(2);
            LinkSystem mg            = new LinkSystem {
                ID_LinkSystem = Convert.ToInt32(number_ramdom)
            };

            _dbBCDH.Entry(mg).State = System.Data.Entity.EntityState.Added;
            _dbBCDH.SaveChanges();
            return(new EmptyResult());
        }
Пример #11
0
        private CuponCode CreateCupon(string userid)
        {
            var tempUser = _dbBCDH.Invoices.Where(x => x.ID_Account == userid && x.Payment_Methods != "PayForAccount").FirstOrDefault();

            if (tempUser != null)
            {
                return(null);
            }
            else
            {
                var       dateCreate = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
                var       code       = new RandomCode().RandomNumber(8);
                CuponCode tempCode   = new CuponCode {
                    Code = code, ContentCode = "KMFristTimeBuy", CreateDate = Convert.ToDateTime(dateCreate), NumberUse = 1, PercentSale = 10, ValueSale = 0, EndDate = Convert.ToDateTime(dateCreate).AddDays(7)
                };
                _dbBCDH.Entry(tempCode).State = System.Data.Entity.EntityState.Added;
                _dbBCDH.SaveChanges();
                return(tempCode);
            }
        }