コード例 #1
0
        public async Task <bool> EditPartner(PartnerRequestModel partnerModel, string cdnPath, string webRootPath)
        {
            if (partnerModel == null)
            {
                throw new ArgumentNullException(nameof(partnerModel));
            }

            var userEntityToUpdate = await _db.Users.GetAsync(partnerModel.PartnerId);

            if (userEntityToUpdate == null)
            {
                return(false);
            }

            var updatedPartnerDescriptionEntity = new DescriptionEntityModel
            {
                Id          = userEntityToUpdate.DescriptionId,
                Description = partnerModel.Description,
            };
            await _db.Descriptions.UpdateAsync(updatedPartnerDescriptionEntity);

            if (partnerModel.PartnerImage != null)
            {
                var newPartnerImageEntity = new ImageEntityModel();
                var cdnContext            = new CdnContext(cdnPath, webRootPath);
                newPartnerImageEntity.FileName = await cdnContext.Upload(partnerModel.PartnerImage);

                newPartnerImageEntity.InsertDate = DateTime.Now;
                newPartnerImageEntity.Id         = await _db.Images.CreateAsync(newPartnerImageEntity);

                userEntityToUpdate.ImageId = newPartnerImageEntity.Id;
            }

            if (!string.IsNullOrEmpty(partnerModel.Password) || !string.IsNullOrWhiteSpace(partnerModel.Password))
            {
                var hashContext       = new HashContext();
                var newHashedPassword = hashContext.MD5(partnerModel.Password);
                userEntityToUpdate.Password = newHashedPassword;
            }
            userEntityToUpdate.Login       = partnerModel.Login;
            userEntityToUpdate.UserName    = partnerModel.Username;
            userEntityToUpdate.Email       = partnerModel.Email;
            userEntityToUpdate.PhoneNumber = partnerModel.PhoneNumber;
            await _db.Users.UpdateAsync(userEntityToUpdate);

            return(true);
        }
コード例 #2
0
        public async Task <IActionResult> Index(LoginViewModel loginModel, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(loginModel));
            }

            var hashContext  = new HashContext();
            var hashPassword = hashContext.MD5(loginModel.Password);
            var userEntity   = await _db.Users.GetUserAsync(loginModel.Login, hashPassword);

            if (userEntity != null)
            {
                await _authenticateContext.SignIn(userEntity);

                return(Redirect(returnUrl ?? "/Home/Index"));
            }

            ModelState.AddModelError("", "Login or password is not correct");
            return(View(loginModel));
        }
コード例 #3
0
        public async Task CreateNewPartner(PartnerRequestModel partnerRequestModel, string cdnPath, string webRootPath)
        {
            if (partnerRequestModel == null)
            {
                throw new ArgumentNullException(nameof(partnerRequestModel));
            }
            var newPartnerDescriptionEntity = new DescriptionEntityModel
            {
                Description = partnerRequestModel.Description,
            };

            newPartnerDescriptionEntity.Id = await _db.Descriptions.CreateAsync(newPartnerDescriptionEntity);

            var newPartnerImageEntity = new ImageEntityModel();
            var cdnContext            = new CdnContext(cdnPath, webRootPath);

            newPartnerImageEntity.FileName = await cdnContext.Upload(partnerRequestModel.PartnerImage);

            newPartnerImageEntity.InsertDate = DateTime.Now;
            newPartnerImageEntity.Id         = await _db.Images.CreateAsync(newPartnerImageEntity);

            var hashContext    = new HashContext();
            var hashedPassword = hashContext.MD5(partnerRequestModel.Password);

            var newPartner = new UserEntityModel()
            {
                DescriptionId = newPartnerDescriptionEntity.Id,
                ImageId       = newPartnerImageEntity.Id,
                InsertDate    = DateTime.Now,
                Login         = partnerRequestModel.Login,
                Password      = hashedPassword,
                Removed       = false,
                RoleId        = RolesContext.Partner,
                UserName      = partnerRequestModel.Username,
                Email         = partnerRequestModel.Email,
                PhoneNumber   = partnerRequestModel.PhoneNumber
            };

            newPartner.Id = await _db.Users.CreateAsync(newPartner);
        }