コード例 #1
0
        public async Task <int> EditAsync(ContactFormMessageEditInputModel input, string userId)
        {
            var entity = await this.contactFormMessagesRepository
                         .All()
                         .FirstOrDefaultAsync(x => x.Id == input.Id);

            if (entity.UserId == userId)
            {
                entity.Name    = input.Name.Trim();
                entity.Phone   = input.Phone.Trim();
                entity.Subject = input.Subject.Trim();
                entity.Message = input.Message.Trim();
            }

            await this.contactFormMessagesRepository.SaveChangesAsync();

            return(entity.Id);
        }
コード例 #2
0
        public async Task <ActionResult <ContactFormMessageExportModel> > Put(
            int id,
            ContactFormMessageEditInputModel input)
        {
            if (id != input.Id)
            {
                return(this.BadRequest());
            }

            var model = await this.contactFormMessagesService.GetByIdAsync <ContactFormMessageExportModel>(id);

            if (model == null)
            {
                return(this.NotFound());
            }

            // var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user = await this.userManager.GetUserAsync(this.User);

            await this.contactFormMessagesService.EditAsync(input, user.Id);

            return(this.NoContent());
        }