Exemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.UserName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

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

                    ProjectS3Entities db        = new ProjectS3Entities();
                    AspNetUsers       userinfor = db.AspNetUsers.SingleOrDefault(t => t.Id == user.Id);

                    userinfor.HoTen       = model.HoTen;
                    userinfor.SoDienThoai = model.SoDienThoai;
                    userinfor.DiaChi      = model.DiaChi;
                    userinfor.avatar      = model.avatar;

                    db.AspNetUsers.Add(userinfor);
                    db.Entry(userinfor).State = System.Data.Entity.EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task setValue(string key, string value)
        {
            MyDynamicvalue info = db.MyDynamicvalue.SingleOrDefault(t => t.Key == key);

            // If dont have the key, add new key
            if (info == null)
            {
                info       = new MyDynamicvalue();
                info.Key   = key;
                info.value = value;
                db.MyDynamicvalue.Add(info);
                await db.SaveChangesAsync();
            }
            else
            {
                // set new value for key
                info.value           = value;
                db.Entry(info).State = System.Data.Entity.EntityState.Modified;
                await db.SaveChangesAsync();
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> updateUserInfor(string hoten, string linkavatar, string sodienthoai, string diachi)
        {
            ProjectS3Entities db     = new ProjectS3Entities();
            string            userid = User.Identity.GetUserId();
            AspNetUsers       user   = db.AspNetUsers.SingleOrDefault(t => t.Id == userid);

            user.HoTen       = hoten;
            user.avatar      = linkavatar;
            user.SoDienThoai = sodienthoai;
            user.DiaChi      = diachi;

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

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> updatecomment(int id, string comment)
        {
            DonHang donhang = db.DonHang.SingleOrDefault(t => t.ID == id);

            if (donhang == null)
            {
                return(HttpNotFound());
            }

            donhang.Comment         = comment;
            db.Entry(donhang).State = System.Data.Entity.EntityState.Modified;
            await db.SaveChangesAsync();

            return(RedirectToAction("chitietdonhang", new { id = id }));
        }
Exemplo n.º 5
0
        public async Task <string> xacnhan(string diachi, string dienthoai, string thoigian, string hoten,
                                           List <SanPhamTrongGioHang> chitiet, string captval, string email)
        {
            //secret that was generated in key value pair
            const string secret = "6LdZwRoTAAAAAEOn-B188a6bk-Yr7wrRhf8yLT6j";

            var client = new WebClient();
            var reply  =
                client.DownloadString(
                    string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}",
                                  secret, captval));

            var captchaResponse = JsonConvert.DeserializeObject <CaptchaResponse>(reply);

            //when response is false check for the error message
            if (captchaResponse.Success == "false")
            {
                if (captchaResponse.ErrorCodes.Count <= 0)
                {
                    return(null);
                }

                var error = captchaResponse.ErrorCodes[0].ToLower();
                switch (error)
                {
                case ("missing-input-secret"):
                    ViewBag.Message = "The secret parameter is missing.";
                    break;

                case ("invalid-input-secret"):
                    ViewBag.Message = "The secret parameter is invalid or malformed.";
                    break;

                case ("missing-input-response"):
                    ViewBag.Message = "The response parameter is missing.";
                    break;

                case ("invalid-input-response"):
                    ViewBag.Message = "The response parameter is invalid or malformed.";
                    break;

                default:
                    ViewBag.Message = "Error occured. Please try again";
                    break;
                }

                return(null);
            }
            else
            {
                // Nếu không phải là người máy
                if (chitiet != null)
                {
                    if (chitiet.Count <= 0)
                    {
                        return(null);
                    }

                    DonHang dh = db.DonHang.Create();

                    if (User.Identity.IsAuthenticated)
                    {
                        dh.UserID = User.Identity.GetUserId();
                    }
                    else
                    {
                        // this is default account for user dont login
                        dh.UserID = null;
                    }

                    dh.SoDienThoai  = dienthoai;
                    dh.ThoiGianGiao = DateTime.Parse(thoigian);
                    dh.TinhTrang    = 1;
                    dh.DiaChiGiao   = diachi;
                    dh.NgayTao      = DateTime.Now;
                    dh.HoTen        = hoten;
                    dh.Email        = email;
                    db.DonHang.Add(dh);

                    for (int i = 0; i < chitiet.Count; i++)
                    {
                        int tempid = chitiet[i].id;

                        ChiTietDonHang item = new ChiTietDonHang();
                        item.IDDonHang   = dh.ID;
                        item.IDSanPham   = chitiet[i].id;
                        item.SoLuong     = chitiet[i].soluong;
                        item.IDBoSanPham = chitiet[i].idbosanpham;
                        item.DioGia      = chitiet[i].dongia;

                        item.Size  = chitiet[i].size;
                        item.Color = chitiet[i].color;

                        db.ChiTietDonHang.Add(item);
                    }

                    await db.SaveChangesAsync();

                    await sendEmail(dh);

                    return(dh.ID.ToString());
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        public async Task <ActionResult> addproduct([Bind(Include = "ID,Ten,DioGia,linkanh,MoTa,TinhTrang,SoLuong,Color,Size,Branches,Type")] SanPham sanpham)
        {
            SanPham item = db.SanPham.Create();

            item.DioGia         = sanpham.DioGia;
            item.linkanh        = sanpham.linkanh;
            item.MoTa           = sanpham.MoTa;
            item.SoLuong        = sanpham.SoLuong;
            item.Ten            = sanpham.Ten;
            item.TinhTrang      = sanpham.TinhTrang;
            item.Color          = sanpham.Color;
            item.Branches       = sanpham.Branches;
            item.Type           = sanpham.Type;
            item.Size           = sanpham.Size;
            item.LastUpdateDate = DateTime.Now;
            item.UserUpdate     = User.Identity.GetUserId();
            db.SanPham.Add(item);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }