예제 #1
0
        public AdvertistmentViewModel Add(AdvertistmentViewModel AdvertistmentVm)
        {
            var Advertistment = Mapper.Map <AdvertistmentViewModel, Advertistment>(AdvertistmentVm);

            _advertistmentRepository.Add(Advertistment);
            return(AdvertistmentVm);
        }
예제 #2
0
        public async Task <IActionResult> Update([FromBody] AdvertistmentViewModel advertistmentVm)
        {
            var hasPermission = await _authorizationService.AuthorizeAsync(User, "ADVERTISMENT", Operations.Update);

            if (hasPermission.Succeeded == false)
            {
                return(new BadRequestObjectResult(CommonConstants.Forbidden));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    Advertistment advertistmentDb = _advertistmentService.DetailDb(advertistmentVm.Id);
                    string        oldPath         = advertistmentDb.Image;
                    if (oldPath != advertistmentVm.Image && !string.IsNullOrEmpty(oldPath))
                    {
                        oldPath.DeletementByString(_env);
                    }
                    advertistmentDb.UpdateAdvertistment(advertistmentVm);
                    _advertistmentService.UpdateDb(advertistmentDb);
                    _advertistmentService.SaveChanges();
                    return(new OkObjectResult(advertistmentVm));
                }
                catch (Exception ex)
                {
                    return(new BadRequestObjectResult(ex.Message));
                }
            }
            return(new BadRequestObjectResult(ModelState));
        }
예제 #3
0
 public static void UpdateAdvertistment(this Advertistment advertistment, AdvertistmentViewModel advertistmentVm)
 {
     advertistment.Name         = advertistmentVm.Name;
     advertistment.Description  = advertistmentVm.Description;
     advertistment.Image        = advertistmentVm.Image;
     advertistment.Url          = advertistmentVm.Url;
     advertistment.PositionId   = advertistmentVm.PositionId;
     advertistment.PageId       = advertistmentVm.PageId;
     advertistment.Status       = advertistmentVm.Status;
     advertistment.DateModified = DateTime.Now;
     advertistment.SortOrder    = advertistmentVm.SortOrder;
 }
예제 #4
0
 public Advertistment(AdvertistmentViewModel advertistmentVm)
 {
     Name         = advertistmentVm.Name;
     Description  = advertistmentVm.Description;
     Image        = advertistmentVm.Image;
     Url          = advertistmentVm.Url;
     PositionId   = advertistmentVm.PositionId;
     PageId       = advertistmentVm.PageId;
     Status       = advertistmentVm.Status;
     DateModified = DateTime.Now;
     SortOrder    = advertistmentVm.SortOrder;
 }
예제 #5
0
        public async Task <IActionResult> Add([FromBody] AdvertistmentViewModel advertistmentVm)
        {
            var hasPermission = await _authorizationService.AuthorizeAsync(User, "ADVERTISMENT", Operations.Create);

            if (hasPermission.Succeeded == false)
            {
                return(new BadRequestObjectResult(CommonConstants.Forbidden));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    advertistmentVm.DateCreated = DateTime.Now;
                    _advertistmentService.Add(advertistmentVm);
                    _advertistmentService.SaveChanges();
                    return(new OkObjectResult(advertistmentVm));
                }
                catch (Exception ex)
                {
                    return(new BadRequestObjectResult(ex.Message));
                }
            }
            return(new BadRequestObjectResult(ModelState));
        }
예제 #6
0
 public void Update(AdvertistmentViewModel product)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 public void Add(AdvertistmentViewModel advertistmentVm)
 {
     _advertistmentRepository.Add(_mapper.Map <Advertistment>(advertistmentVm));
 }