示例#1
0
        // GET: Users/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorklyUser worklyUser = db.WorklyUsers.Find(id);

            if (worklyUser == null)
            {
                return(HttpNotFound());
            }
            return(View(worklyUser));
        }
示例#2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Name = model.Name, Surname = model.Surname, Phone = model.Phone
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                await UserManager.AddToRoleAsync(user.Id, model.Role);

                Rating rating = new Rating();
                rating.Sum     = 5;
                rating.Times   = 1;
                rating.Average = 5;
                var worklyUser = new WorklyUser {
                    Email = model.Email, Name = model.Name, Surname = model.Surname, Phone = model.Phone, Rating = rating, Role = model.Role
                };
                var tempList = new List <Review>();
                var rev      = new Review();
                ///
                rev.Comment = "comment goes here";
                ///

                tempList.Add(rev);

                //  worklyUser.Review = tempList;

                jobSystemContext.WorklyUsers.Add(worklyUser);
                jobSystemContext.SaveChanges();

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

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // 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", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#3
0
        // GET: Users/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorklyUser worklyUser = db.WorklyUsers.Find(id);

            if (worklyUser == null)
            {
                return(HttpNotFound());
            }
            worklyUser.ReviewList = db.Review.Where(u => u.Email == worklyUser.Email).ToList <Review>();
            return(View(worklyUser));
        }
示例#4
0
        public ActionResult Edit([Bind(Include = "WorklyUserId,Email,Rating, Review")] WorklyUser worklyUser)
        {
            var review = new Review();

            review.ReviewId = worklyUser.WorklyUserId;
            review.Email    = worklyUser.Email;
            review.Comment  = worklyUser.Review.Comment;
            db.Review.Add(review);
            var user = db.WorklyUsers.Find(worklyUser.WorklyUserId);
            int a    = worklyUser.Rating.Rate;

            user.Rating.Sum += worklyUser.Rating.Rate;
            user.Rating.Times++;
            user.Rating.Average = user.Rating.Sum / user.Rating.Times;

            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(worklyUser));
        }