Esempio n. 1
0
 public void CreateAndUpdatePromoter(AddPromotersDTO dto)
 {
     if (dto.PromoterId != 0)
     {
         var promoter = dBContext.Promoters.FirstOrDefault(x => x.Id == dto.PromoterId);
         if (promoter != null)
         {
             promoter.CompanyId     = dto.CompanyId;
             promoter.ContactNumber = dto.ContactNumber;
             promoter.Address       = dto.Address;
             promoter.EmailAddress  = dto.EmailAddress;
             promoter.PromoterName  = dto.PromoterName;
             dBContext.SaveChanges();
         }
     }
     else
     {
         var promoter = new Promoter()
         {
             CompanyId     = dto.CompanyId,
             ContactNumber = dto.ContactNumber,
             Address       = dto.Address,
             EmailAddress  = dto.EmailAddress,
             PromoterName  = dto.PromoterName
         };
         dBContext.Promoters.Add(promoter);
         dBContext.SaveChanges();
     }
 }
Esempio n. 2
0
        public IActionResult CreatePromoter(AddPromotersVM addPromotersVM)
        {
            if (!ModelState.IsValid)
            {
                ShowToaster("Please fill required fields", ToasterLevel.Danger);
                return(RedirectToAction("Promoters", "Company", new { companyId = addPromotersVM.CompanyId }));
            }
            var             config = new MapperConfiguration(cfg => cfg.CreateMap <AddPromotersVM, AddPromotersDTO>());
            var             mapper = new Mapper(config);
            AddPromotersDTO dto    = mapper.DefaultContext.Mapper.Map <AddPromotersDTO>(addPromotersVM);

            _userService.CreateAndUpdatePromoter(dto);
            ShowToaster("Promoter created successfully", ToasterLevel.Success);

            return(RedirectToAction("Promoters", "Company", new { companyId = dto.CompanyId }));
        }