コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,ProjectId,DictionaryId,Title,Content,Orders")] tblProjectDetail tblProjectDetail)
        {
            using (var d = new LandSoftEntities())
            {
                var detail =
                    d.tblProjectDetail.Where(
                        t =>
                        t.ProjectId == tblProjectDetail.ProjectId &&
                        t.DictionaryId == tblProjectDetail.DictionaryId);

                if (detail.Any())
                {
                    foreach (var item in detail)
                    {
                        d.tblProjectDetail.Remove(item);
                    }

                    d.SaveChanges();
                }
            }

            db.tblProjectDetail.Add(tblProjectDetail);
            db.SaveChanges();



            ViewBag.DictionaryId = new SelectList(db.tblDictionary, "Id", "Title", tblProjectDetail.DictionaryId);
            ViewBag.ProjectId    = new SelectList(db.tblProject, "Id", "Title", tblProjectDetail.ProjectId);
            return(RedirectToAction("Create", new { id = tblProjectDetail.ProjectId }));
        }
コード例 #2
0
        public ActionResult Update(tblLand model, IEnumerable <HttpPostedFileBase> listImage)
        {
            var dba = new LandSoftEntities();
            var la  = dba.tblLand.Find(model.Id);

            if (la == null)
            {
                return(RedirectToAction("Update"));
            }

            foreach (var item in listImage)
            {
                if (item == null)
                {
                    continue;
                }

                var newName = item.FileName.Insert(item.FileName.LastIndexOf('.'), $"{DateTime.Now:_ddMMyyyy}");

                var path = Server.MapPath("~/Uploads/News/" + newName);

                item.SaveAs(path);

                var a = new tblImage
                {
                    Image        = newName,
                    URL          = "/Uploads/News/" + newName,
                    LandId       = model.Id,
                    DictionaryId = 47
                };
                db.tblImage.Add(a);
            }
            model.Area            = string.Empty;
            model.Area            = Request["DienTich"];
            model.CustomerId      = la.CustomerId;
            model.CreateDate      = la.CreateDate;
            db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public override string[] GetRolesForUser(string username)
        {
            var db = new LandSoftEntities();

            var roles = db.AspNetUsers.Include(t => t.AspNetRoles).FirstOrDefault(t => t.UserName == username);

            if (roles == null)
            {
                return new[] { "User" }
            }
            ;

            var roleUser = roles.AspNetRoles.FirstOrDefault();

            if (roleUser != null)
            {
                return new [] { roleUser.Name }
            }
            ;

            return(new[] { "User" });
        }
コード例 #4
0
        public ActionResult Register(UserViewModel form, HttpPostedFileBase imageUser)
        {
            ViewBag.WardId     = new SelectList(_db.tblWard, "Id", "Name");
            ViewBag.ProvinceId = new SelectList(_db.tblProvince, "Id", "Name");
            ViewBag.DistrictId = new SelectList(_db.tblDistrict, "Id", "Name");

            var customer = _db.tblCustomer.Where(t => t.Email.Equals(form.Email.Trim()));

            if (customer.Any())
            {
                ModelState.AddModelError("Email", "Email này đã có người sử dụng. Vui lòng sử dụng email khác");
            }

            customer = _db.tblCustomer.Where(t => t.Username == form.Username.Trim());
            if (customer.Any())
            {
                ModelState.AddModelError("Username", "Username đã có người sử dụng. Vui lòng sử dụng Username khác!");
            }

            if (!ModelState.IsValid)
            {
                return(View(form));
            }

            using (var data = new LandSoftEntities())
            {
                form.SetPassword(form.Password);
                var user = new tblCustomer
                {
                    Address    = form.Address,
                    Birthday   = form.Birthday,
                    Email      = form.Email,
                    ProvinceId = form.ProvinceId,
                    DistrictId = form.DistrictId,
                    WardId     = form.WardId,
                    Skype      = form.Skype,
                    Sex        = (form.Gender == EnumGender.Nam) ? true : false,
                    Username   = form.Username,
                    Password   = form.Password,
                    FullName   = form.FullName,
                    Phone      = form.Phone,
                };
                data.tblCustomer.Add(user);
                data.SaveChanges();

                using (var database = new LandSoftEntities())
                {
                    var role = database.AspNetRoles.Where(t => t.Name.Equals("User")).ToList();

                    var userAsp = new AspNetUsers
                    {
                        Id                = Guid.NewGuid().ToString(),
                        UserName          = form.Username,
                        SecurityStamp     = BCrypt.Net.BCrypt.HashString(form.Username),
                        PhoneNumber       = form.Phone,
                        LockoutEndDateUtc = DateTime.MaxValue,
                        PasswordHash      = form.Password,
                        Email             = form.Email,
                        AspNetRoles       = role
                    };

                    database.AspNetUsers.Add(userAsp);
                    database.SaveChanges();
                }
            }
            return(RedirectToAction("Login"));
        }