public IHttpActionResult Update(AnnouncementBindingModel abm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var announcement = Mapper.Map <AnnouncementBindingModel, Announcement>(abm);

                    _announcementService.Update(announcement);

                    announcement = _announcementService.GetAll().FirstOrDefault(p => p.Id == announcement.Id);

                    abm = Mapper.Map <Announcement, AnnouncementBindingModel>(announcement);

                    return(Ok(abm));
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
            return(Ok(StatusCode(HttpStatusCode.BadRequest)));
        }
        public IHttpActionResult Delete(Guid id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var abm = new AnnouncementBindingModel()
                    {
                        Id = id
                    };
                    var announcement = Mapper.Map <AnnouncementBindingModel, Announcement>(abm);
                    _announcementService.Delete(announcement.Id);

                    return(Ok());
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
            return(Ok(StatusCode(HttpStatusCode.BadRequest)));
        }
Exemple #3
0
        public async Task <IActionResult> Create([FromBody] AnnouncementBindingModel model)
        {
            var entity = _mapper.Map <Announcement>(model);

            entity.CreatedBy = UserId;
            entity.ImageUrl  = ""; // should this be in the form?

            await _repository.AddAsync(entity);

            return(Ok());
        }
Exemple #4
0
        public async Task <IActionResult> Update([FromBody] AnnouncementBindingModel model)
        {
            var entity = await _repository.FindAsync(model.Id);

            if (entity == null)
            {
                return(BadRequest(new BadRequestResponseModel(ErrorTypes.BadRequest, ErrorMessages.ItemNotFound)));
            }

            entity.Title       = model.Title;
            entity.Description = model.Description;
            entity.CallAction  = model.CallAction;
            entity.LinkUrl     = model.LinkUrl;
            entity.Expiration  = model.Expiration;
            entity.UpdatedAt   = DateTime.Now;
            entity.UpdatedBy   = UserId;

            await _repository.UpdateAsync(entity);

            return(Ok());
        }