Ejemplo n.º 1
0
        public async Task <ActionResult> FeatureAppsAdd(FeatureAppView model)
        {
            using (var db = new TDContext())
            {
                if (!ModelState.IsValid)
                {
                    return(Json(Js.Error(this.GetModelStateError())));
                }
                if (await db.FeatureApps.AnyAsync(x => x.Name == model.Name))
                {
                    return(Json(TD.Global.FeatureAppExits.GetError()));
                }
                var data = new FeatureApp()
                {
                    Name = model.Name
                };
                db.FeatureApps.Add(data);
                var str = await db.SaveDatabase();

                if (str != null)
                {
                    return(Json(str.GetError()));
                }
                return(Json(Js.SuccessRedirect("Đã thêm chức năng", "/admin/apps/AppFeaturesAdd")));;
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> FeatureAppsEdit(FeatureAppView model)
        {
            using (var db = new TDContext())
            {
                if (!ModelState.IsValid)
                {
                    return(Json(Js.Error(this.GetModelStateError())));
                }



                var data = await db.FeatureApps.FindAsync(model.Id);

                if (data == null)
                {
                    return(Json(string.Format("Không tìm thấy chức năng : {0} Mã :{1}", model.Name, model.Id).GetError()));
                }
                data.Name            = model.Name;
                db.Entry(data).State = EntityState.Modified;
                var result = await db.SaveDatabase();

                if (result.NotNull())
                {
                    result.GetError();
                }
                return(Json(Js.SuccessRedirect("Đã cập nhật chức năng", "/admin/apps/FeatureApps")));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Edit(DPageViewModel view)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }
            var data = db.DPages.Find(view.Id);

            view.Content = await view.Content.GetValidHtml();

            if (data == null)
            {
                return(Json(Js.Error("Trang không tồn tại")));
            }
            data.IsPage          = view.isPage;
            data.Content         = view.Content;
            data.Name            = view.Name;
            data.ModifyId        = User.Identity.GetUserId();
            data.LastModify      = DateTime.UtcNow;
            db.Entry(data).State = System.Data.Entity.EntityState.Modified;
            var str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(Js.Error(str)));
            }
            return(Json(Js.SuccessRedirect("Đã lưu trang", "/admin/config")));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> ChangePassword(string OldPassword, string NewPassword)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;
            if (user.PasswordHash.ToDecrypt() != OldPassword)
            {
                return(Json(Js.Error(TD.Global.PasswordNotValid)));
            }
            ;
            user.PasswordHash    = NewPassword.ToEncrypt();
            db.Entry(user).State = EntityState.Modified;
            await db.SaveChangesAsync();

            user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user != null)
            {
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
            }
            return(Json(Js.SuccessComponent(Global.YourPasswordHasBeenSet, "profiles")));;
        }
Ejemplo n.º 5
0
        public async Task<ActionResult> Edit(GalleryEditViewModel model)
        {
            string result = "";
            var data = db.Galleries.Find(model.Id);
            if (data == null) return Json(LanguageDB.NotFound.GetError());
            if (!string.IsNullOrEmpty(model.ImageData))
            {
                var image = db.AppFiles.Find(model.AppFileId);
                if (image != null)
                {
                    image.FullPath.DeleteFile();
                    db.AppFiles.Remove(image);
                }
                var saveFile = await db.SaveImage(model.ImageData, "galleries", null);
                if (!saveFile.OK) return Json(Js.Error(saveFile.Message));
                data.AppFiles.Add(saveFile.Image);

                db.Entry(image).State = System.Data.Entity.EntityState.Modified;
                result += saveFile.Message;
            }
            data.Name = model.Name;
            data.Subtitle = model.Subtitle;
            data.Link = model.Link;
            data.VideoLink = model.VideoLink;
            data.InHome = model.InHome;
            data.ButtonText = model.ButtonText;
            db.Entry(data).State = System.Data.Entity.EntityState.Modified;
            var str = await db.SaveMessageAsync();
            if (str != null) return Json(Js.Error(str));
            return Json(Js.SuccessRedirect("Đã cập nhật Gallery: " + result, "/admin/home/config", 10));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            using (var db = new TDContext())
            {
                User data = db.Users.Find(id);
                if (data != null)
                {
                    if (data.AvatarId != null)
                    {
                        var image = data.Avatar;
                        db.AppFiles.Remove(image);
                        string filePath = Server.MapPath("~/data/img/users/" + id);// + string.Format(Properties.Resources.UserImageLink, id));
                        filePath.DeleteFile();
                    }
                    db.Users.Remove(data);
                    var str = await db.SaveMessageAsync();

                    if (str != null)
                    {
                        return(Json(str.GetError()));
                    }

                    return(Json(Js.SuccessRedirect(Global.UserRemoved, "/admin/users")));
                }
                return(Json(Js.Error()));
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Login(string UserName, string Password, string ReturnUrl)
        {
            //if (!ModelState.IsValid)
            //{
            //    return Json(Js.Error(this.GetModelStateError()));
            //}
            var result = await SignInManager.PasswordSignInAsync(UserName, Password, true, shouldLockout : true);

            switch (result)
            {
            case SignInStatus.Success:
                if (!string.IsNullOrEmpty(ReturnUrl))
                {
                    return(Json(Js.SuccessRedirect("Wellcome Back " + UserName, ReturnUrl)));
                }
                else
                {
                    return(Json(Js.Reload("Wellcome Back" + UserName)));
                };

            case SignInStatus.LockedOut:
                return(Json(Js.Error(Global.YourAccountHasBeenLockout)));;

            case SignInStatus.RequiresVerification:
                return(Json(Js.Warning(Global.HelpVerifyAccount, "/Account/SendCode")));;

            case SignInStatus.Failure:
            default:
                return(Json(Js.Error(Global.InvalidLoginInfo)));;
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> RegisterFast(string Email, string Password)
        {
            if (ModelState.IsValid)
            {
                var user = new User {
                    Email = Email, UserName = Email
                };
                var result = await UserManager.CreateAsync(user, Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", string.Format(Global.PleaseVerifyYourAccount, "https://cnstandat.net", callbackUrl));

                    return(Json(Js.Warning(string.Format(Global.HelpVerifyAccount, Email))));
                }

                return(Json((result.GetError())));;
            }
            return(Json(Js.Error(Global.GenericError)));;
            // If we got this far, something failed, redisplay form
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> ChangeEmail(string Email, string Password)
        {
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;
            if (user.PasswordHash.ToDecrypt() != Password)
            {
                return(Json(Js.Error(TD.Global.PasswordNotValid)));
            }
            if (db.Users.Any(x => x.Id != user.Id && x.Email == Email))
            {
                return(Json(Js.Error(TD.Global.EmailUsed)));
            }
            ;
            user.Email           = Email;
            user.EmailConfirmed  = false;
            db.Entry(user).State = EntityState.Modified;
            await db.SaveChangesAsync();

            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

            string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            await UserManager.SendEmailAsync(user.Id, "Confirm your account", string.Format(Global.PleaseVerifyYourAccount, "https://cnstandat.net", callbackUrl));

            return(Json(Js.Warning(string.Format(Global.HelpVerifyAccount, Email), "profiles")));;
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> ChangeSign(string Sign, string Password)
        {
            if (string.IsNullOrEmpty(Sign))
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;
            if (user.PasswordHash.ToDecrypt() != Password)
            {
                return(Json(Js.Error(TD.Global.PasswordNotValid)));
            }
            ;
            user.Sign = await Sign.GetValidHtml();

            db.Entry(user).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(Json(Js.SuccessComponent(TD.Global.SignChanged, "profiles")));;
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> AppVersionsAdd(AppVersionView model)
        {
            using (var db = new TDContext())
            {
                if (!ModelState.IsValid)
                {
                    return(Json(Js.Error(this.GetModelStateError())));
                }
                var version = model.Selected.ToEnum <LicenseType>();


                var data = await db.AppVersions.FindAsync(model.AppId, version);

                if (data != null)
                {
                    return(Json("Đã tồn tại phiên bản ứng dụng này".GetError()));
                }
                model.Version = version;
                data          = new AppVersion(model);
                db.AppVersions.Add(data);
                var str = await db.SaveDatabase();

                if (str != null)
                {
                    return(Json(str.GetError()));
                }
                return(Json(Js.SuccessRedirect("Đã thêm phiên bản", TD.Properties.Resources.AdminAppsLink + "/AppVersionsEdit?AppId=" + model.AppId + "&Version=" + version)));
            }
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Create(DPageViewModel view)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }
            var data = db.DPages.Find(view.Id);

            view.Content = await view.Content.GetValidHtml();

            if (data != null)
            {
                return(Json(Js.Error("Trang đã tồn tại")));
            }
            data            = new Models.DPage(view);
            data.IsPage     = true;
            data.CreatorId  = User.Identity.GetUserId();
            data.LastModify = DateTime.UtcNow;
            db.DPages.Add(data);
            var str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(Js.Error(str)));
            }
            return(Json(Js.SuccessRedirect("Đã thêm trang mới", "/admin/config")));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> Create(PartnerEditView model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }
            if (await db.Partners.AnyAsync(x => x.Name == model.Name))
            {
                return(Json(Js.Error(TD.Global.PartnerExist)));
            }
            var data = new Partner(model);

            if (!string.IsNullOrEmpty(model.ImageData))
            {
                var saveFile = model.ImageData.WriteImageString(Server.MapPath("~/data/img/partners"));
                if (!saveFile.Success)
                {
                    return(Json(Js.Error(saveFile.Error)));
                }
                data.Logo = "/data/img/partners/" + saveFile.FileName;
            }
            db.Partners.Add(data);
            var str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(Js.Error(str)));
            }
            return(Json(Js.SuccessRedirect("Thêm mới khách hàng thành công", "/admin/partners/edit/" + data.Id)));
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> ChangeName(string FullName, string Password)
        {
            if (string.IsNullOrEmpty(FullName))
            {
                return(Json("Vui lòng nhập họ tên".GetError()));
            }
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;
            if (user.PasswordHash.ToDecrypt() != Password)
            {
                return(Json(LanguageDB.PasswordNotValid.GetError()));
            }
            ;
            user.FullName        = FullName;
            db.Entry(user).State = EntityState.Modified;
            var str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(str.GetError()));
            }
            return(Json(Js.SuccessComponent(TD.Global.NameChanged, "profiles")));;
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> SetPassword(string NewPassword)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;
            if (!string.IsNullOrEmpty(user.PasswordHash))
            {
                return(Json(Js.Error(TD.Global.PasswordNotValid)));
            }

            var result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), NewPassword);

            if (result.Succeeded)
            {
                user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(Json(Js.Success(Global.YourPasswordHasBeenSet)));;
            }

            return(Json(Js.Error(Global.GenericError)));;
        }
Ejemplo n.º 16
0
        public async Task <ActionResult> GenData(string modelName, int?count)
        {
            if (string.IsNullOrEmpty(modelName))
            {
                return(Json(Js.Error("Vui lòng chọn dữ liệu")));
            }
            modelName = modelName.ToLower();
            var dbHelper = new DBHelper();

            if (modelName == "tagblog")
            {
                var result = await dbHelper.GerenateTagBlogs(db);

                if (!string.IsNullOrEmpty(result))
                {
                    return(Json(Js.Error(result)));
                }
            }
            else if (modelName == "blog")
            {
                var str = await dbHelper.GerenateBlogs(db, User.Identity.GetUserId(), count ?? 10);

                if (str != null)
                {
                    return(Json(str.GetError()));
                }
            }
            else
            {
                return(Json(Js.Error("Chưa hỗ trợ")));
            }
            return(Json(Js.Success(string.Format("Đã tạo dữ liệu : {0} số lượng {1}", modelName, count ?? 10))));
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> VerifyPhoneNumber(string PhoneNumber, string Code)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(Global.PleaseCheckYourCode)));;
            }
            string phoneNumber = UserManager.GetPhoneNumber(User.Identity.GetUserId());

            var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), PhoneNumber);

            if (code == Code)
            {
                using (var db = new TDContext())
                {
                    var dbUser = db.Users.Find(User.Identity.GetUserId());
                    dbUser.PhoneNumber          = PhoneNumber;
                    dbUser.PhoneNumberConfirmed = true;
                    db.SaveChanges();
                }

                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(Json(Js.SuccessLoad(Global.YourPhoneNumberHasBeenSet)));;
            }
            return(Json(Js.Error(Global.GenericError)));;
        }
Ejemplo n.º 18
0
        public ActionResult UploadImage(string ImageData)
        {
            var file = ImageData.Base64MimeType();

            if (file == null)
            {
                return(Json(Js.Error("Dữ liệu không đúng")));
            }

            var saveFile = ImageData.WriteImageString("upload\\" + User.Identity.GetUserId());

            if (!saveFile.Success)
            {
                return(Json(new {
                    Success = false,
                    Message = saveFile.Message
                }));
            }
            db.AppFiles.Add(new AppFile(new DBHelper().GetAppFileId(db), saveFile.FileName));
            return(Json(new
            {
                Success = true,
                FileName = "/data/img/upload/" + User.Identity.GetUserId() + "/" + saveFile.FileName
            }));
        }
Ejemplo n.º 19
0
        public async Task <ActionResult> VerifyPhone(string PhoneNumber, string Code)
        {
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;

            string phoneNumber = UserManager.GetPhoneNumber(User.Identity.GetUserId());

            var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), PhoneNumber);

            if (code != Code)
            {
                return(Json(Js.Error("Mã xác minh không chính xác")));
            }
            ;

            user.PhoneNumber          = PhoneNumber;
            user.PhoneNumberConfirmed = true;
            db.Entry(user).State      = EntityState.Modified;
            await db.SaveChangesAsync();

            user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user != null)
            {
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
            }
            return(Json(Js.SuccessComponent(Global.YourPhoneNumberHasBeenSet, "profiles")));;
        }
Ejemplo n.º 20
0
        public async Task <ActionResult> Edit(UserViewModel model)
        {
            var db          = new TDContext();
            var currentUser = User.Identity.GetUserId();

            var data = db.Users.Find(model.Id);

            if (data == null)
            {
                return(Json(Js.Error("Không tìm thấy người dùng")));
            }



            var lstSelect = await GetSelectRole(model.RoleId, db);

            var current = data.Roles.ToList();



            foreach (var item in current)
            {
                if (!lstSelect.Contains(item.RoleId))
                {
                    data.Roles.Remove(item);// UserManager.RemoveFromRoleAsync(data.Id, item);
                }
            }
            data.UserName        = model.UserName;
            data.Email           = model.Email;
            data.CantSay         = model.CantSay;
            data.Sign            = model.Sign;
            data.PasswordHash    = model.Password.ToEncrypt();
            db.Entry(data).State = EntityState.Modified;



            foreach (var item in lstSelect)
            {
                if (!data.Roles.Any(x => x.RoleId == item))
                {
                    data.Roles.Add(new IdentityUserRole
                    {
                        UserId = data.Id,
                        RoleId = item
                    });
                }
            }

            db.Entry(data).State = EntityState.Modified;
            var str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(str.GetError()));
            }
            return(Json(Js.SuccessRedirect(Global.UserChanged, "/admin/users")));
        }
Ejemplo n.º 21
0
        public async Task <ActionResult> VersionFeatureAppsEdit(VersionFeatureEditModel model)
        {
            using (var db = new TDContext())
            {
                if (!ModelState.IsValid)
                {
                    return(Json(Js.Error(this.GetModelStateError())));
                }
                var FeatureAppId = model.Selected;

                var find = db.FeatureApps.Find(FeatureAppId);
                if (find == null)
                {
                    find = db.FeatureApps.FirstOrDefault(x => x.Name == model.Selected);
                    if (find == null)
                    {
                        find = new FeatureApp
                        {
                            Name = model.Selected
                        };
                        db.FeatureApps.Add(find);
                        var str = await db.SaveDatabase();

                        if (str != null)
                        {
                            return(Json(str.GetError()));
                        }
                    }
                    FeatureAppId = find.Id;
                }
                model.FeatureAppId = FeatureAppId;
                var data = await db.VersionFeatureApps.FindAsync(model.AppId, model.Version, FeatureAppId);

                if (data == null)
                {
                    data = new VersionFeature(model);
                    db.VersionFeatureApps.Add(data);
                    var str = await db.SaveDatabase();

                    if (str != null)
                    {
                        return(Json(str.GetError()));
                    }
                }
                data.Content         = model.Content;
                db.Entry(data).State = EntityState.Modified;
                var result = await db.SaveDatabase();

                if (result.NotNull())
                {
                    result.GetError();
                }
                return(Json(Js.SuccessRedirect(TD.Global.VersionFeatureAppChanged, string.Format("{0}/VersionsEdit?AppId={1}&Version={2}", TD.Properties.Resources.AdminAppEditLink, model.AppId, model.Version))));
            }
        }
Ejemplo n.º 22
0
        public ActionResult SaveCurrentData()
        {
            var fileData = Server.MapPath("~/data/default.json");

            if (!fileData.IsExits())
            {
                return(Json(Js.Error("Chưa có file mẫu")));
            }
            var data = Newtonsoft.Json.JsonConvert.DeserializeObject(fileData.LoadFromFile());

            return(Json(Js.Success("Đang khởi tạo")));
        }
Ejemplo n.º 23
0
        public async Task <ActionResult> AppFeaturesAdd(AppFeatureView model)
        {
            using (var db = new TDContext())
            {
                if (!ModelState.IsValid)
                {
                    return(Json(Js.Error(this.GetModelStateError())));
                }
                var FeatureAppId = model.Selected;

                var find = db.FeatureApps.Find(FeatureAppId);
                if (find == null)
                {
                    find = db.FeatureApps.FirstOrDefault(x => x.Name == model.Selected);
                    if (find == null)
                    {
                        find = new FeatureApp
                        {
                            Name = model.Selected
                        };
                        db.FeatureApps.Add(find);
                        var str = await db.SaveDatabase();

                        if (str != null)
                        {
                            return(Json(str.GetError()));
                        }
                    }
                    FeatureAppId = find.Id;
                }


                var data = await db.AppFeatures.FindAsync(model.AppId, FeatureAppId);

                if (data != null)
                {
                    return(Json(Global.FeatureAppAppExist.GetError()));
                }

                data         = new AppFeature(model.AppId, FeatureAppId);
                data.Content = model.Content;
                data.Order   = model.Order;
                db.AppFeatures.Add(data);
                var str2 = await db.SaveDatabase();

                if (str2.NotNull())
                {
                    return(Json(str2.GetError()));
                }
                return(Json(Js.SuccessRedirect(Global.FeatureAppAppAdded, "AppFeaturesAdd/" + model.AppId)));
            }
        }
Ejemplo n.º 24
0
        public async Task <ActionResult> Create(UserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(this.GetModelStateError().GetError()));
            }

            var db          = new TDContext();
            var currentUser = User.Identity.GetUserId();
            var lstSelect   = await GetSelectRole(model.RoleId, db);

            if (await db.Users.AnyAsync(x => x.UserName == model.UserName))
            {
                return(Json(Js.Error(TD.Global.UserNameUsed)));
            }

            var data = new User(model.UserName);

            data.CantSay      = model.CantSay;
            data.Sign         = model.Sign;
            data.Email        = model.Email;
            data.PasswordHash = model.Password.ToEncrypt();
            db.Users.Add(data);
            var str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(str.GetError()));
            }

            foreach (var item in lstSelect)
            {
                if (!data.Roles.Any(x => x.RoleId == item))
                {
                    data.Roles.Add(new IdentityUserRole
                    {
                        UserId = data.Id,
                        RoleId = item
                    });
                }
            }
            db.Entry(data).State = EntityState.Modified;
            str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(str.GetError()));
            }
            return(Json(Js.SuccessRedirect(TD.Global.UserInserted, "/admin/users")));
        }
Ejemplo n.º 25
0
        public async Task <ActionResult> Edit(AppEditModel dataModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }
            var create = await new AppDB().Edit(dataModel, User.Identity.GetUserId());

            if (!create.Success)
            {
                return(Json(create.Message.GetError()));
            }
            return(Json(Js.SuccessRedirect(string.Format(CData.AppConfig.AppEdit, CData.AppConfig.AppCreateLink, CData.AppConfig.AppLink), CData.AppConfig.AppLink)));
        }
Ejemplo n.º 26
0
        public async Task <ActionResult> ChangePhone(string PhoneNumber, string Password)
        {
            if (!ModelState.IsValid)
            {
                return(Json(Js.Error(this.GetModelStateError())));
            }

            if (UserManager.SmsService == null)
            {
                return(Json(Js.Error(TD.Global.SMSOff)));
            }
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;
            if (db.Users.Any(x => x.Id != user.Id && x.PhoneNumber == PhoneNumber))
            {
                return(Json(LanguageDB.PhoneNumberExits.GetError()));
            }

            var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), PhoneNumber);

            string phoneNumber = string.Format("+{0}", PhoneNumber);
            var    message     = new IdentityMessage
            {
                Destination = phoneNumber,
                Body        = "Mã xác nhận của bạn là : " + code
            };

            try
            {
                TwilioHelper.CreateNumber(phoneNumber);
                await UserManager.SmsService.SendAsync(message);
            }
            catch (Exception e)
            {
                await UserManager.SmsService.SendAsync(new IdentityMessage
                {
                    Destination = "+84985569705",
                    Body        = e.Message
                });

                return(Json(Js.Error(e.Message)));;
            }
            return(Json(Js.WarningComponent("Vui lòng xác nhận mã điện thoại", "verifyphone", PhoneNumber)));;
        }
Ejemplo n.º 27
0
        public async Task <ActionResult> Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Json(Js.Error("Không tìm thấy thảo luận")));
            }
            var data = await db.Comments.FindAsync(id);

            if (data == null)
            {
                return(Json(Js.Error("Không tìm thấy thảo luận")));
            }
            db.Comments.Remove(data);
            db.SaveChanges();
            return(Json(Js.SuccessRedirect("Đã xóa thảo luận", "/admin/blogs/edit/" + data.BlogId)));
        }
Ejemplo n.º 28
0
        public async Task <ActionResult> RemovePhoneNumber()
        {
            var result = await UserManager.SetPhoneNumberAsync(User.Identity.GetUserId(), null);

            if (!result.Succeeded)
            {
                return(Json(Js.Error(Global.CantRemoveYourPhoneNumber)));;
            }
            var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user != null)
            {
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
            }
            return(Json(Js.SuccessLoad(Global.YourPhoneNumberHasBeenSet)));;
        }
Ejemplo n.º 29
0
        public async Task <ActionResult> SetAvatar(string ImageData)
        {
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user == null)
            {
                return(Json(Js.Error(TD.Global.UserNotFound)));
            }
            ;
            if (string.IsNullOrEmpty(ImageData))
            {
                return(Json(Js.Error("Dữ liệu ảnh trống")));
            }
            if (string.IsNullOrEmpty(user.AvatarId))
            {
                var saveFile = ImageData.WriteImageString(("users"));
                if (!saveFile.Success)
                {
                    return(Json(Js.Error(saveFile.Message)));
                }

                var image = await ImageHelper.SaveImage(db, ImageData, "users", null);

                if (!image.OK)
                {
                    return(Json(image.Message.GetError()));
                }
                user.Avatar          = image.Image;
                db.Entry(user).State = EntityState.Modified;
                var result = await db.SaveMessageAsync();

                if (!string.IsNullOrEmpty(result))
                {
                    return(Json(Js.Error(result)));
                }
            }
            else
            {
                var saveFile = await ImageHelper.SaveImage(db, ImageData, "users", user.AvatarId);

                if (!saveFile.OK)
                {
                    return(Json(Js.Error(saveFile.Message)));
                }
            }
            return(Json(Js.SuccessLoad(Global.YourAvatarHasBeenSet)));;
        }
Ejemplo n.º 30
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,FullName")] TagBlog tag)
        {
            if (await db.TagBlogs.AnyAsync(x => x.Id != tag.Id && x.FullName == tag.FullName))
            {
                return(Json(Js.Error(Global.TagBlogUsed)));
            }
            ;
            tag.Name            = tag.FullName.GetSafeName();
            db.Entry(tag).State = EntityState.Modified;
            var str = await db.SaveMessageAsync();

            if (str != null)
            {
                return(Json(str.GetError()));
            }
            return(Json(Js.SuccessRedirect(TD.Global.TagBlogChanged, "/admin/tagblogs")));;
        }