Пример #1
0
        public async Task <IActionResult> NewEntry([FromBody] MaintenanceEntryViewModel value)
        {
            if (ModelState.IsValid)
            {
                return(Ok(await _maintenanceRequestsDataProvider.AddMaintenanceEntryAsync(User, value)));
            }

            return(BadRequest(new { Errors = ModelState.ToErrorCollection() }));
        }
Пример #2
0
        public async Task <MaintenanceEntryViewModel> UpdateMaintenanceEntryAsync(ClaimsPrincipal user, MaintenanceEntryViewModel viewModel)
        {
            var portfolioId = await GetPortfolioIdForUserAsync(user);

            var entity = await(from maintenanceEntry in Context.MaintenanceEntries
                               join maintenanceRequest in Context.MaintenanceRequests.Include(x => x.PropertyDetails) on maintenanceEntry.MaintenanceRequestId equals maintenanceRequest.Id
                               where maintenanceRequest.PropertyDetails.PortfolioId == portfolioId && maintenanceRequest.Id == viewModel.MaintenanceRequestId
                               select maintenanceEntry)
                         .SingleAsync();

            entity.MapFrom(viewModel);
            await Context.SaveChangesAsync();

            return(new MaintenanceEntryViewModel(entity));
        }
Пример #3
0
        public async Task <MaintenanceEntryViewModel> AddMaintenanceEntryAsync(ClaimsPrincipal user, MaintenanceEntryViewModel maintenanceEntry)
        {
            var portfolioId = await GetPortfolioIdForUserAsync(user);

            var applicationUser = await user.GetApplicationUserAsync(Context);

            var maintenanceRequest = await Context.MaintenanceRequests.Include(x => x.PropertyDetails)
                                     .SingleOrDefaultAsync(c => c.PropertyDetails.PortfolioId == portfolioId && c.Id == maintenanceEntry.MaintenanceRequestId);

            if (maintenanceRequest != null)
            {
                var entity = new MaintenanceEntry
                {
                    Created              = DateTime.Now,
                    Description          = maintenanceEntry.Description,
                    MaintenanceRequestId = maintenanceRequest.Id,
                    Status = maintenanceEntry.Status,
                    UserId = applicationUser.Id
                };

                await Context.AddAsync(entity);

                await Context.SaveChangesAsync();

                return(new MaintenanceEntryViewModel(entity)
                {
                    User = new ApplicationUserViewModel(applicationUser)
                });
            }

            return(null);
        }