Esempio n. 1
0
        // GET: Projects/Edit/5
        public async Task <IActionResult> Edit(int?id, string?projecttitle)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FreeLancers4User user = await _userManager.GetUserAsync(User);

            if (!user.Role.Equals("client"))
            {
                return(NotFound());
            }

            ViewBag.Text = projecttitle;

            var work = await _context.Work.FindAsync(id);//changes the name at the url place

            if (work == null)
            {
                return(NotFound());
            }

            if (!work.Owner.Equals(user))
            {
                return(NotFound());
            }

            return(View(work));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new FreeLancers4User {
                    UserName = Input.Email, Email = Input.Email, Role = Input.Role.ToLower()
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a class=\"error\" href='{HtmlEncoder.Default.Encode(callbackUrl)}'>CLICKING HERE</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Esempio n. 3
0
        public async Task <IActionResult> Accept(int id)
        {
            var work = await _context.Work.FindAsync(id);

            if (work == null)
            {
                return(NotFound());
            }

            FreeLancers4User user = await _userManager.GetUserAsync(User);

            if (work.AssignedTo != null)
            {
                ModelState.AddModelError("Assigned", "The job has already been assigned to someone else.");
            }
            else
            {
                work.Assigned   = user;
                work.WorkStatus = "Assigned";
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.History.Add(new History {
                        Project = work,
                    });

                    _context.Update(work);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WorkExists(work.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 4
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var work = await _context.Work.FindAsync(id);

            FreeLancers4User user = await _userManager.GetUserAsync(User);

            if (!work.Owner.Equals(user))
            {
                return(NotFound());
            }

            _context.Work.Remove(work);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        private async Task LoadAsync(FreeLancers4User user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                FistName    = user.FirstName,
                LastName    = user.LastName,
                DOB         = user.DOB,
                Proffesion  = user.Proffesion,
                PhoneNumber = phoneNumber
            };
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, [Bind("ProjectTitle,Description,Skills,Price,DueDate,ContactEmail")] Work work)
        {
            if (id != work.ID)
            {
                return(NotFound());
            }

            FreeLancers4User user = await _userManager.GetUserAsync(User);

            if (!work.Owner.Equals(user))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(work);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WorkExists(work.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(work));
        }
Esempio n. 7
0
        // GET: Projects/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var work = await _context.Work
                       .FirstOrDefaultAsync(m => m.ID == id);

            if (work == null)
            {
                return(NotFound());
            }

            FreeLancers4User user = await _userManager.GetUserAsync(User);

            if (!work.Owner.Equals(user))
            {
                return(NotFound());
            }

            return(View(work));
        }