public Response <bool> DeleteConfirmed(int?id)
        {
            try
            {
                var model = _context.ContentManagement.Find(id);
                if (model == null)
                {
                    return(new Response <bool>(Constants.NOT_FOUND_CODE, false, Constants.NOT_FOUND));
                }
                model.IsDeleted = true;
                var webPath      = _hostingEnvironment.WebRootPath;
                var pathToDelete = webPath + model.ImageUrl;
                // TO DO: remove file

                /*
                 *
                 */

                _context.ContentManagement.Remove(model);
                _context.SaveChanges();
                Message = Toast.SucsessToast();
                return(new Response <bool>(Constants.SUCCESS_CODE, true, Constants.SUCCESS));
            }
            catch (Exception exc)
            {
                return(new Response <bool>(Constants.SOMETHING_WRONG_CODE, false, GetExceptionMessage(exc)));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

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

                    Customer customer = new Customer();
                    customer.UserId = user.Id;
                    _context.Customer.Add(customer);
                    _context.SaveChanges();
                    await _userManager.AddToRoleAsync(user, "Customer");

                    var contentAppName = _context.ContentManagement.Where(cm => cm.Name == "app_name")
                                         .FirstOrDefault();
                    string AppName = contentAppName == null ? "Fuel Services" : contentAppName.DisplayName;

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    EmailBodyDefaultParams emailBodyDefaultParams = _context.EmailBodyDefaultParams
                                                                    .Where(e => e.EmailTypeName == "confirm_mail").FirstOrDefault();
                    string body = EmailSender.CreateEmailBody(emailBodyDefaultParams);
                    body = body.Replace("{callbackurl}", HtmlEncoder.Default.Encode(callbackUrl));
                    var simpleResponse = EmailSender.SendEmail(Input.Email, AppName, body);
                    TempData.Set("Toast", simpleResponse);
                    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> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            var email = await _userManager.GetEmailAsync(user);

            if (Input.Email != email)
            {
                var setEmailResult = await _userManager.SetEmailAsync(user, Input.Email);

                if (!setEmailResult.Succeeded)
                {
                    var userId = await _userManager.GetUserIdAsync(user);

                    throw new InvalidOperationException($"Unexpected error occurred setting email for user with ID '{userId}'.");
                }
            }

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            if (Input.PhoneNumber != phoneNumber)
            {
                var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    var userId = await _userManager.GetUserIdAsync(user);

                    throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
                }
            }
            Customer customer = _context.Customer.Where(c => c.UserId == user.Id).FirstOrDefault();

            if (customer != null)
            {
                if (Input.file != null)
                {
                    FileInfo fi          = new FileInfo(Input.file.FileName);
                    var      newFilename = "P" + customer.Id + "_" + string.Format("{0:d}",
                                                                                   (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                    var webPath = _hostingEnvironment.WebRootPath;
                    var path    = Path.Combine("", webPath + @"\uploads\customers\" + newFilename);

                    var pathToSave = @"/uploads/customers/" + newFilename;

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await Input.file.CopyToAsync(stream);
                    }
                    customer.ImageUrl = pathToSave;
                }

                customer.FirstName = Input.FirstName;
                customer.LastName  = Input.LastName;
                customer.CountryId = Input.CountryId;

                _context.Update(customer);
                _context.SaveChanges();
            }
            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = "Your profile has been updated";
            return(RedirectToPage());
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            ReturnUrl = Url.Content("~/");
            if (ModelState.IsValid)
            {
                if (User.Identity.IsAuthenticated)
                {
                    await _signInManager.SignOutAsync();

                    _logger.LogInformation("User logged out.");
                }
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

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

                    var UserManager = _serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                    var RoleManager = _serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >();

                    var roleResult = await RoleManager.FindByNameAsync("Supplier");

                    if (roleResult == null)
                    {
                        roleResult = new ApplicationRole("Supplier");
                        await RoleManager.CreateAsync(roleResult);
                    }
                    await UserManager.AddToRoleAsync(user, "Supplier");

                    FuelSupplier fuelSupplier = new FuelSupplier();
                    fuelSupplier.UserId    = user.Id;
                    fuelSupplier.Name      = Input.Name;
                    fuelSupplier.CountryId = Input.CountryId;
                    fuelSupplier.IsMiddler = Input.IsMiddler;

                    if (Input.file != null)
                    {
                        FileInfo fi          = new FileInfo(Input.file.FileName);
                        var      newFilename = "P" + fuelSupplier.Id + "_" + string.Format("{0:d}",
                                                                                           (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                        var webPath = _hostingEnvironment.WebRootPath;
                        var path    = Path.Combine("", webPath + @"\uploads\suppliers\" + newFilename);

                        var pathToSave = @"/uploads/suppliers/" + newFilename;

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await Input.file.CopyToAsync(stream);
                        }
                        fuelSupplier.ImageUrl = pathToSave;
                    }

                    SupplierContact supplierContact1 = new SupplierContact();
                    supplierContact1.ContactId = 3;
                    supplierContact1.Value     = Input.CompanyWebSite;

                    SupplierContact supplierContact2 = new SupplierContact();
                    supplierContact2.ContactId = 18;
                    supplierContact2.Value     = _context.Country.Find(Input.CountryId) != null?
                                                 _context.Country.Find(Input.CountryId).Name : "";

                    fuelSupplier.SupplierContact = new List <SupplierContact>();
                    fuelSupplier.SupplierContact.Add(supplierContact1);
                    fuelSupplier.SupplierContact.Add(supplierContact2);

                    SupplierContactPerson supplierContactPerson = new SupplierContactPerson();
                    supplierContactPerson.JobTitle = Input.Position;
                    supplierContactPerson.Name     = Input.Name;
                    SupplierContactPersonContact supplierContactPersonContact = new SupplierContactPersonContact();
                    supplierContactPersonContact.ContactId             = 7;
                    supplierContactPersonContact.Value                 = Input.Email;
                    supplierContactPerson.SupplierContactPersonContact = new List <SupplierContactPersonContact>();
                    supplierContactPerson.SupplierContactPersonContact.Add(supplierContactPersonContact);

                    fuelSupplier.SupplierContactPerson = new List <SupplierContactPerson>();
                    fuelSupplier.SupplierContactPerson.Add(supplierContactPerson);

                    _context.FuelSupplier.Add(fuelSupplier);
                    _context.SaveChanges();

                    var contentAppName = _context.ContentManagement.Where(cm => cm.Name == "app_name")
                                         .FirstOrDefault();
                    string AppName = contentAppName == null ? "Fuel Services" : contentAppName.DisplayName;

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    EmailBodyDefaultParams emailBodyDefaultParams = _context.EmailBodyDefaultParams
                                                                    .Where(e => e.EmailTypeName == "confirm_mail").FirstOrDefault();
                    string body = EmailSender.CreateEmailBody(emailBodyDefaultParams);
                    body = body.Replace("{callbackurl}", HtmlEncoder.Default.Encode(callbackUrl));
                    var simpleResponse = EmailSender.SendEmail(Input.Email, AppName, body);
                    TempData.Set("Toast", simpleResponse);
                    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. 5
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    Customer customer = new Customer();
                    customer.UserId = user.Id;
                    _context.Customer.Add(customer);
                    _context.SaveChanges();
                    var contentAppName = _context.ContentManagement.Where(cm => cm.Name == "app_name")
                                         .FirstOrDefault();
                    string AppName = contentAppName == null ? "Fuel Services" : contentAppName.DisplayName;

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    EmailBodyDefaultParams emailBodyDefaultParams = _context.EmailBodyDefaultParams
                                                                    .Where(e => e.EmailTypeName == "confirm_mail").FirstOrDefault();
                    string body = EmailSender.CreateEmailBody(emailBodyDefaultParams);
                    body = body.Replace("{callbackurl}", HtmlEncoder.Default.Encode(callbackUrl));
                    var simpleResponse = EmailSender.SendEmail(Input.Email, AppName, body);
                    TempData.Set("Toast", simpleResponse);

                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }