using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.ViewModel;
using DotVVM.Framework.Runtime.Filters;
using ElectroShop.Models;
using ElectroShop.Services;
using ElectroShop.DAL.Entities;
using ElectroShop.Resources;

namespace ElectroShop.ViewModels.User
{
    [Authorize(Roles = "Administrator")]
    public class DeleteViewModel : MasterPageViewModel
    {
        private readonly UserService userService;

        public UserModel User { get; set; }
        public string Username { get; set; }

        public DeleteViewModel(UserService userService)
        {
            this.userService = userService;
        }

        public override async Task PreRender()
        {


            await base.PreRender();
        }

        public override Task Init()
        {
            Username = Context.Parameters["Username"].ToString();
            User = userService.GetUserModelByName(Username);
            return base.Init();
        }

        public void Delete()
        {
            try
            {
                userService.DeleteUser(User);
            }
            catch
            {
                Context.RedirectToRoute("UserManagement");
            }
            finally
            {
                Context.RedirectToRoute("UserManagement");
            }

        }
    }
}
