Пример #1
0
        public AdvertiserViewModel Add(AdvertiserViewModel AdvertiserViewModel)
        {
            var advertiser = Mapper.Map <AdvertiserViewModel, Advertiser>(AdvertiserViewModel);

            _advertiserRepository.Add(advertiser);
            _unitOfWork.Commit();
            return(AdvertiserViewModel);
        }
        public async Task UpdateAsync(AdvertiserViewModel model)
        {
            var dbAdvertiser = await _repo.Advertisers.GetByIdAsync(model.Id);

            if (dbAdvertiser == null)
            {
                return;
            }
            dbAdvertiser = MapUpdate().CreateMapper().Map(model, dbAdvertiser);
            await _repo.SaveAsync();
        }
Пример #3
0
        public void Update(AdvertiserViewModel AdvertiserViewModel)
        {
            var temp = _advertiserRepository.FindById(AdvertiserViewModel.KeyId);

            if (temp != null)
            {
                temp.BrandName  = AdvertiserViewModel.BrandName;
                temp.Status     = AdvertiserViewModel.Status;
                temp.UrlToBrand = AdvertiserViewModel.UrlToBrand;
            }
        }
Пример #4
0
        public AdvertiserViewModel GetBysId(string id)
        {
            var query = _advertiserRepository.FindAll(p => p.UserBy);
            var _data = new AdvertiserViewModel();

            foreach (var item in query)
            {
                if ((item.UserFK.ToString()) == id)
                {
                    _data = Mapper.Map <Advertiser, AdvertiserViewModel>(item);
                }
            }
            return(_data);
        }
 public IActionResult SaveEntity(AdvertiserViewModel advertiserVm)
 {
     if (!ModelState.IsValid)
     {
         IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
         return(new BadRequestObjectResult(allErrors));
     }
     else
     {
         if (advertiserVm.KeyId == 0)
         {
             _advertiserService.Add(advertiserVm);
         }
         else
         {
             _advertiserService.Update(advertiserVm);
         }
         _advertiserService.Save();
         return(new OkObjectResult(advertiserVm));
     }
 }
        public IActionResult ImportFiles(IList <IFormFile> files)
        {
            var userid     = _generalFunctionController.Instance.getClaimType(User, CommonConstants.UserClaims.Key);
            var advertiser = new AdvertiserViewModel();

            if (Guid.TryParse(userid, out var guid))
            {
                advertiser = _advertiserService.GetBysId(userid);
            }

            if (files != null && files.Count > 0)
            {
                List <string> fileName = new List <string>();
                for (int i = 0; i < files.Count; i++)
                {
                    var file      = files[i];
                    var extension = Path.GetExtension(file.FileName);
                    var filename  = DateTime.Now.ToString("yyyyMMddHHmmss");
                    filename = (filename + extension).ToString();
                    string folder = _hostingEnvironment.WebRootPath + $@"\images\advertiser\" + advertiser.BrandName + "\\content";
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }
                    string filePath = Path.Combine(folder, filename);
                    fileName.Add(Path.Combine($@"\images\advertiser\" + advertiser.BrandName + "\\content", filename).Replace($@"\", $@"/"));

                    using (FileStream fs = System.IO.File.Create(filePath))
                    {
                        file.CopyTo(fs);
                        fs.Flush();
                    }
                }
                _advertisementContentService.Save();
                return(new OkObjectResult(fileName));
            }
            return(new NoContentResult());
        }
        public async Task <IActionResult> Register(RegisterViewModel model, UserViewModel userViewModel, AdvertiserViewModel advertiserViewModel, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new Data.Entities.User
                {
                    UserName     = model.Email,
                    Email        = model.Email,
                    FullName     = userViewModel.FullName,
                    Address      = userViewModel.Address,
                    DateCreated  = DateTime.Now,
                    DateModified = DateTime.Now,
                    PhoneNumber  = userViewModel.PhoneNumber,
                    Gender       = Data.Enums.Gender.Other,
                    Status       = Data.Enums.Status.InActive,
                    UserTypeFK   = Const_UserType.Advertiser,
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme, nameof(AccountController.ConfirmEmail), "Advertiser");

                    var content = "Hãy nhấp vào link này để xác nhận tài khoản quảng cáo Bé Yêu Bookstore: " + callbackUrl;

                    SendConfirmEmail(model.Email, content);
                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    //await _userManager.AddToRoleAsync(user, "Quảng cáo"); // add vao role
                    var advertiser = new Advertiser();
                    advertiser.UserFK     = user.Id;
                    advertiser.BrandName  = advertiserViewModel.BrandName;
                    advertiser.UrlToBrand = advertiserViewModel.UrlToBrand;
                    await _userManager.AddToRoleAsync(user, "Quảng cáo"); // add vao role

                    _context.Advertisers.Add(advertiser);
                    _context.SaveChanges();

                    return(new RedirectResult(Url.Action("WaitingConfirmation", "BeyeuBookstore")));
                }
            }

            // If we got this far, something failed, redisplay form
            return(new RedirectResult(Url.Action("SignUp", "BeyeuBookstore")));
        }
        public async Task <IHttpActionResult> Put(AdvertiserViewModel model)
        {
            await _advertiserBuilder.UpdateAsync(model);

            return(Ok());
        }