Example #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            string AvatarImg = "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png";



            if (ModelState.IsValid)
            {
                User user = new User()
                {
                    UserName  = model.CreateUser.Username,
                    FirstName = model.CreateUser.FirstName,
                    LastName  = model.CreateUser.LastName,
                    Email     = model.CreateUser.Email,
                    Birthdate = model.CreateUser.BirthDate,
                    Gender    = _genderService.GetGenderById(model.CreateUser.GenderId),
                    ImgUrl    = AvatarImg,
                    IsBlocked = false
                };
                var result = await _userManager.CreateAsync(user, model.CreateUser.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "User");

                    return(RedirectToAction(nameof(Login)));
                }
                else
                {
                    AddIdendityErrors(result);
                }
            }
            model.Genders = _genderService.GetGenders().ToList();
            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Trainee trainee = new Trainee()
                    {
                        TraineeId   = Input.TraineeId,
                        Gender      = await _genderService.GetGenderById(Input.GenderId),
                        GenderId    = Input.GenderId,
                        Address     = Input.Address,
                        DoB         = Input.DoB,
                        Email       = Input.Email,
                        PhoneHome   = Input.PhoneHome,
                        PhoneMobile = Input.PhoneMobile,
                        FullName    = Input.FullName
                    };

                    var status = await _traineeService.Update(trainee);
                }
                return(new RedirectToPageResult("Index"));
            }
            catch (OzoneException ex)
            {
                return(RedirectToPage("/Error", ex.Message));
            }
            catch (Exception ex)
            {
                return(RedirectToPage("/Error", ex.Message));
            }
        }
        public IActionResult GetGenderById(int id)
        {
            try
            {
                Gender gender = _genderService.GetGenderById(id);
                if (gender == null)
                {
                    _logger.Error($"Gender with id: {id} not found in db");
                    return(NotFound());
                }

                return(Ok(gender));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/gender/GetGenderById/" + id.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
Example #4
0
        public static void AddAdministratorUser(IApplicationBuilder app)
        {
            using (var @scope = app.ApplicationServices.CreateScope())
            {
                try
                {
                    UserManager <User> _userManager   = scope.ServiceProvider.GetRequiredService <UserManager <User> >();
                    IGenderService     _genderService = scope.ServiceProvider.GetRequiredService <IGenderService>();

                    string AvatarImg = "https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_1280.png";

                    bool IsInRole = false;

                    foreach (var user in _userManager.Users)
                    {
                        if (_userManager.IsInRoleAsync(user, "Admin").Result)
                        {
                            IsInRole = true;
                        }
                    }

                    if (IsInRole == false)
                    {
                        User user = new User()
                        {
                            UserName  = "******",
                            FirstName = "Admin",
                            LastName  = "Admin",
                            Email     = "*****@*****.**",
                            Birthdate = DateTime.Now,
                            Gender    = _genderService.GetGenderById(1),
                            ImgUrl    = AvatarImg,
                            IsBlocked = false
                        };

                        var result = _userManager.CreateAsync(user, "Admin1").Result;

                        if (result.Succeeded)
                        {
                            var AddInRole = _userManager.AddToRoleAsync(user, "Admin").Result;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Example #5
0
        public async Task <IActionResult> OnGet(int id)
        {
            var trainee = await _traineeService.GetTraineeById(id, includeDetails : true);

            Input = new InputModel()
            {
                TraineeId   = trainee.TraineeId,
                FullName    = trainee.FullName,
                PhoneHome   = trainee.PhoneHome,
                PhoneMobile = trainee.PhoneMobile,
                DoB         = trainee.DoB.ToString("dd/MM/yyyy"),
                Address     = trainee.Address,
                Email       = trainee.Email,
                Gender      = (await _genderService.GetGenderById(trainee.GenderId)).Description
            };
            return(Page());
        }
        public ActionResult UpdateProfile()
        {
            UpdateProfileViewModel updateProfileViewModel = new UpdateProfileViewModel();
            AdminProfileViewModel  profile = (AdminProfileViewModel)Session["EmployeeObj"];

            updateProfileViewModel.EmployeeID   = profile.EmployeeID;
            updateProfileViewModel.FirstName    = profile.FirstName;
            updateProfileViewModel.MiddleName   = profile.MiddleName;
            updateProfileViewModel.LastName     = profile.LastName;
            updateProfileViewModel.Image        = profile.Image;
            updateProfileViewModel.AddressLine1 = profile.AddressLine1;
            updateProfileViewModel.AddressLine2 = profile.AddressLine2;
            updateProfileViewModel.AddressLine3 = profile.AddressLine3;
            updateProfileViewModel.Nationality  = profile.Nationality;
            updateProfileViewModel.MobileNumber = profile.MobileNumber;
            updateProfileViewModel.DateOfBirth  = profile.DateOfBirth;
            updateProfileViewModel.GenderID     = profile.GenderID;
            updateProfileViewModel.GenderList   = genderService.GenderList();
            updateProfileViewModel.GenderName   = genderService.GetGenderById(profile.GenderID);
            return(View(updateProfileViewModel));
        }
Example #7
0
        public BaseWebServiceResponse Add(AddProductViewModel model)
        {
            var response = new BaseWebServiceResponse();

            if (_productService.ProductNameExists(model.ProductName))
            {
                response.Error.Name    = "Product Name";
                response.Error.Message = "Product Name exists";

                return(response);
            }

            decimal price;

            if (!decimal.TryParse(model.Price, out price))
            {
                response.ActionSuccessful = false;
                response.Error.Name       = "Price";
                response.Error.Message    = "Price must be a decimal value e.g. 100.00";

                return(response);
            }

            List <IFormFile> listFiles = new List <IFormFile>()
            {
                model.Image1,
                model.Image2,
                model.Image3,
                model.Image4,
            };

            bool fileExists = _fileValidationWebService.FileExists(listFiles);

            if (!fileExists)
            {
                response.Error.Name    = "Images";
                response.Error.Message = "At least one Image must be uploaded.";

                return(response);
            }

            bool filesAreJpg = _fileValidationWebService.IsFileFormatJpg(listFiles);

            if (!filesAreJpg)
            {
                response.Error.Name    = "Images";
                response.Error.Message = "Files must be jpg file format.";

                return(response);
            }

            //TODO: Refactor this - Mapper or Helper
            var productDto = mapper.Map <AddProductViewModel, ProductDTO>(model);

            productDto.Gender    = _genderService.GetGenderById(Convert.ToInt32(model.SelectedGender));
            productDto.Price     = price;
            productDto.HeroImage = ProductHelper.WriteImageToBytes(model.HeroImage);
            productDto.Images.Add(new ProductImageDTO()
            {
                Image = ProductHelper.WriteImageToBytes(model.Image1)
            });
            productDto.Images.Add(new ProductImageDTO()
            {
                Image = ProductHelper.WriteImageToBytes(model.Image2)
            });
            productDto.Images.Add(new ProductImageDTO()
            {
                Image = ProductHelper.WriteImageToBytes(model.Image3)
            });
            productDto.Images.Add(new ProductImageDTO()
            {
                Image = ProductHelper.WriteImageToBytes(model.Image4)
            });
            productDto.Sizes = JsonConvert.DeserializeObject <List <ProductSizeDTO> >(model.SizesJson);

            if (!_productService.Add(productDto))
            {
                response.Error.Name    = "Add Product";
                response.Error.Message = "There was a problem while attempting to add the Product, please try again. If this problem persists, please contact support.";

                return(response);
            }

            response.ActionSuccessful = true;
            response.SuccessMessage   = "Product added successfully!";
            return(response);
        }