public IActionResult GetDetail(int id,
                                       [FromQuery] BookingQueryProjection projection,
                                       [FromQuery] BookingQueryOptions options)
        {
            var getManagerType = projection.GetFieldsArr().Contains(BookingQueryProjection.MANAGER_TYPE);

            projection = new BookingQueryProjection {
                fields = BookingQueryProjection.DETAIL
            };
            var entity = _service.GetBookingDetail(id, projection);

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateGetBookingDetail(entity, User, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var obj = _service.GetBookingDynamic(entity, projection, options);

            if (getManagerType)
            {
                obj["manager_type"] = validationData.TempData["manager_type"];
            }
            return(Ok(AppResult.Success(data: obj)));
        }
Пример #2
0
        public async Task <IActionResult> UpdateImage(int id,
                                                      [FromForm] UpdateProductModelImageModel model)
        {
            var entity = _service.ProductModels.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateProductModelImage(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var(relPath, fullPath) = _service.GetProductModelImagePath(entity,
                                                                       Settings.Instance.UploadFolderPath, Settings.Instance.WebRootPath);
            var oldRelPath = entity.Image;

            _service.UpdateProductModelImage(entity, relPath);
            context.SaveChanges();
            // must be in transaction
            var ev = _ev_service.UpdateProductModelImage(entity, User);

            context.SaveChanges();
            await _service.SaveReplaceProductModelImage(model, fullPath, Settings.Instance.WebRootPath, oldRelPath);

            return(Created($"/{relPath}",
                           AppResult.Success(relPath)));
        }
        public IActionResult FeedbackBooking(int id, FeedbackBookingModel model)
        {
            var entity = _service.Bookings.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateFeedbackBooking(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var fromStatus = entity.Status;

            using (var trans = context.Database.BeginTransaction())
            {
                _service.FeedbackBooking(model, entity);
                var history = _service.CreateHistoryForFeedbackBooking(entity, entity.BookMember);
                //log event
                var ev = _sysService.GetEventForBookingProcessing(history);
                _sysService.CreateAppEvent(ev);
                //end log event
                context.SaveChanges();
                trans.Commit();
            }
            //notify managers (if any)
            //var managerIds = _memberService.QueryManagersOfArea(entity.Room.BuildingAreaCode)
            //    .Select(o => o.UserId).ToList();
            //if (managerIds.Count > 0)
            //    await NotiHelper.Notify(managerIds, managerNoti);
            return(NoContent());
        }
Пример #4
0
 public IActionResult Delete(int id)
 {
     try
     {
         var entity = _service.ProductModels.Id(id).FirstOrDefault();
         if (entity == null)
         {
             return(NotFound(AppResult.NotFound()));
         }
         var validationData = _service.ValidateDeleteProductModel(User, entity);
         if (!validationData.IsValid)
         {
             return(BadRequest(AppResult.FailValidation(data: validationData)));
         }
         _service.DeleteProductModel(entity);
         _service.DeleteProductModelFolder(entity, Settings.Instance.UploadFolderPath, Settings.Instance.WebRootPath);
         context.SaveChanges();
         // must be in transaction
         var ev = _ev_service.DeleteProductModel(entity, User);
         context.SaveChanges();
         return(NoContent());
     }
     catch (DbUpdateException e)
     {
         _logger.Error(e);
         return(BadRequest(AppResult.DependencyDeleteFail()));
     }
 }
Пример #5
0
 public IActionResult Delete(string code)
 {
     try
     {
         var entity = _service.Departments.Code(code).FirstOrDefault();
         if (entity == null)
         {
             return(NotFound(AppResult.NotFound()));
         }
         var validationData = _service.ValidateDeleteDepartment(User, entity);
         if (!validationData.IsValid)
         {
             return(BadRequest(AppResult.FailValidation(data: validationData)));
         }
         using (var trans = context.Database.BeginTransaction())
         {
             _service.DeleteDepartment(entity);
             //log event
             var ev = _sysService.GetEventForDeleteDepartment(
                 $"Admin {UserEmail} deleted department {entity.Name}", User,
                 entity);
             _sysService.CreateAppEvent(ev);
             //end log event
             context.SaveChanges();
             trans.Commit();
         }
         return(NoContent());
     }
     catch (DbUpdateException e)
     {
         _logger.Error(e);
         return(BadRequest(AppResult.FailValidation(data: new ValidationData()
                                                    .Fail(code: AppResultCode.DependencyDeleteFail))));
     }
 }
Пример #6
0
        public IActionResult Update(string code, UpdateDepartmentModel model)
        {
            var entity = _service.Departments.Code(code).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateDepartment(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            using (var transaction = context.Database.BeginTransaction())
            {
                _service.UpdateDepartment(entity, model);
                //log event
                var ev = _sysService.GetEventForUpdateDepartment(
                    $"Admin {UserEmail} updated department {entity.Name}",
                    User, model);
                _sysService.CreateAppEvent(ev);
                //end log event
                context.SaveChanges();
                transaction.Commit();
            }
            return(NoContent());
        }
 public IActionResult Delete(int id)
 {
     try
     {
         var entity = _service.DeviceConfigs.Id(id).FirstOrDefault();
         if (entity == null)
         {
             return(NotFound(AppResult.NotFound()));
         }
         var validationData = _service.ValidateDeleteDeviceConfig(User, entity);
         if (!validationData.IsValid)
         {
             return(BadRequest(AppResult.FailValidation(data: validationData)));
         }
         _service.DeleteDeviceConfig(entity);
         context.SaveChanges();
         if (entity.IsCurrent)
         {
             Startup.SetCurrentConfig(null);
         }
         return(NoContent());
     }
     catch (DbUpdateException e)
     {
         _logger.Error(e);
         return(BadRequest(AppResult.DependencyDeleteFail()));
     }
 }
Пример #8
0
        public async Task <IActionResult> RemoveRole(string name)
        {
            var entity = _service.GetRoleByName(name);

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateDeleteRole(User, entity);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var result = await _service.RemoveRoleAsync(entity);

            if (result.Succeeded)
            {
                return(Ok(AppResult.Success(result)));
            }
            foreach (var err in result.Errors)
            {
                ModelState.AddModelError(err.Code, err.Description);
            }
            return(BadRequest(AppResult.FailValidation(ModelState)));
        }
 public IActionResult Delete(int id)
 {
     try
     {
         var entity = _service.Resources.Id(id).FirstOrDefault();
         if (entity == null)
         {
             return(NotFound(AppResult.NotFound()));
         }
         var validationData = _service.ValidateDeleteResource(User, entity);
         if (!validationData.IsValid)
         {
             return(BadRequest(AppResult.FailValidation(data: validationData)));
         }
         _service.DeleteResource(entity);
         context.SaveChanges();
         // must be in transaction
         var ev = _ev_service.DeleteResource(entity, User);
         context.SaveChanges();
         return(NoContent());
     }
     catch (DbUpdateException e)
     {
         _logger.Error(e);
         return(BadRequest(AppResult.DependencyDeleteFail()));
     }
 }
        public IActionResult ChangeRoomHangingStatus(
            ChangeRoomHangingStatusModel model)
        {
            Room entity = null;

            if (model.Code != null)
            {
                entity = _service.Rooms.Code(model.Code).FirstOrDefault();
                if (entity == null)
                {
                    return(NotFound(AppResult.NotFound()));
                }
            }
            var validationData = _service.ValidateChargeRoomHangingStatus(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            if (entity != null && _service.ChangeRoomHangingStatus(entity, model.Hanging, UserId))
            {
                context.SaveChanges();
            }
            else
            {
                _service.ReleaseHangingRoomByHangingUserId(model.ReleaseHangingUserId);
                context.SaveChanges();
            }
            return(NoContent());
        }
Пример #11
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public AppResult <UserLoginInfoModel> UserLogin(LoginRequest request)
        {
            var appResult = new AppResult <UserLoginInfoModel>();

            var sysuser = _sysuser.FirstOrDefault(a => a.LoginName == request.LoginName);

            if (sysuser == null)
            {
                appResult.NotFound("账户未找到!");
                return(appResult);
            }

            var isPassed = sysuser.CheckPassword(request.Password);

            if (!isPassed)
            {
                appResult.Fail("密码不正确!");
                return(appResult);
            }

            appResult.Data = new UserLoginInfoModel()
            {
                Id   = sysuser.Id,
                Name = sysuser.LoginName
            };
            appResult.Done();

            return(appResult);
        }
        public async Task <IActionResult> Update(string id, UpdateMemberModel model)
        {
            var entity = _service.Members.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateMember(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            using (var transaction = context.Database.BeginTransaction())
            {
                var user = entity.User;
                _service.UpdateMember(entity, model);
                user = _identityService.UpdateUser(user, model);
                if (model.UpdateDepartmentMembers.Any(o => o.IsManager == true) ||
                    model.UpdateAreaMembers.Any(o => o.IsManager == true))
                {
                    model.Roles = model.Roles ?? new HashSet <string>();
                    model.Roles.Add(RoleName.MANAGER);
                }
                var result = await _identityService.UpdateUserAsync(user);

                if (result.Succeeded && model.Roles != null && model.Roles.Count() > 0)
                {
                    var oldRoles = await _identityService.GetRolesOfUserAsync(user);

                    result = await _identityService.RemoveUserFromRolesAsync(user, oldRoles);

                    if (result.Succeeded)
                    {
                        result = await _identityService.AddRolesForUserAsync(user, model.Roles);
                    }
                }
                if (!result.Succeeded)
                {
                    foreach (var err in result.Errors)
                    {
                        ModelState.AddModelError(err.Code, err.Description);
                    }
                    var builder = ResultHelper.MakeInvalidAccountRegistrationResults(ModelState);
                    return(BadRequest(builder));
                }
                _logger.CustomProperties(User).Info("Update user");
                //log event
                var ev = _sysService.GetEventForUpdateUser(
                    $"Admin has updated a user information",
                    UserId);
                _sysService.CreateAppEvent(ev);
                //end log event
                context.SaveChanges();
                transaction.Commit();
            }
            return(NoContent());
        }
        public async Task <IActionResult> CheckRoomStatus(string code,
                                                          CheckRoomStatusModel model)
        {
            var entity = _service.Rooms.Code(code).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateCheckRoomStatus(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            AppEvent ev;

            using (var trans = context.Database.BeginTransaction())
            {
                var oldNote   = entity.Note;
                var oldStatus = entity.IsAvailable;
                _service.CheckRoomStatus(model, entity);
                //log event
                ev = _sysService.GetEventForRoomProcessing(
                    $"{UserEmail} has changed the status of room {entity.Code}",
                    "Room_CheckStatus", UserId, new
                {
                    old_note   = oldNote,
                    old_status = oldStatus,
                    new_note   = entity.Note,
                    new_status = entity.IsAvailable
                });
                _sysService.CreateAppEvent(ev);
                //end log event
                trans.Commit();
                context.SaveChanges();
            }
            //notify managers
            var notiData = new Dictionary <string, string>
            {
                { "event", ev.Type },
                { "id", entity.Code.ToString() }
            };
            var managerIds = _memberService.QueryManagersOfDepartment(entity.DepartmentCode)
                             .Union(_memberService.QueryManagersOfArea(entity.BuildingAreaCode))
                             .Select(o => o.UserId).ToList();

            if (managerIds.Count > 0)
            {
                await NotiHelper.Notify(managerIds, new Notification
                {
                    Title = $"Status of room {entity.Code} has been changed",
                    Body  = $"{UserEmail} has changed the status of room {entity.Code}. Pressed for more detail"
                }, data : notiData);
            }
            return(NoContent());
        }
Пример #14
0
        public async Task <IActionResult> PushNoti(PushNotiModel model)
        {
            var user = _identityService.Users.ByEmail(model.Email).FirstOrDefault();

            if (user == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var result = await _adminService.PushNotiToUser(user, model);

            return(Ok(AppResult.Success(result)));
        }
        public async Task <IActionResult> UpdateBooking(int id, UpdateBookingModel model)
        {
            var entity = _service.Bookings.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var member         = _memberService.Members.Id(UserId).FirstOrDefault();
            var validationData = _service.ValidateUpdateBooking(User, member, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var      fromStatus = entity.Status;
            AppEvent ev;

            using (var trans = context.Database.BeginTransaction())
            {
                _service.UpdateBooking(model, entity);
                var history = _service.CreateHistoryForUpdateBooking(entity, member);
                //log event
                ev = _sysService.GetEventForBookingProcessing(history);
                _sysService.CreateAppEvent(ev);
                //end log event
                context.SaveChanges();
                trans.Commit();
            }
            //notify using members
            var notiData = new Dictionary <string, string>
            {
                { "event", ev.Type },
                { "id", entity.Id.ToString() }
            };
            var updatePerson = fromStatus == BookingStatusValues.PROCESSING ? "department manager" :
                               "location manager";
            var usingMemberIds = entity.UsingMemberIds.Split('\n');
            var notiMemberIds  = usingMemberIds.Where(o => o != UserId).ToList();
            await NotiHelper.Notify(notiMemberIds, new Notification
            {
                Title = $"Booking {entity.Code} has been updated by your {updatePerson}",
                Body  = $"{UserEmail} has just updated your booking of room {entity.RoomCode}. Press for more detail"
            }, data : notiData);

            return(NoContent());
        }
        public async Task <IActionResult> Delete(string id)
        {
            try
            {
                var entity = _service.Members.Id(id).FirstOrDefault();
                if (entity == null)
                {
                    return(NotFound(AppResult.NotFound()));
                }
                var validationData = _service.ValidateDeleteMember(User, entity);
                if (!validationData.IsValid)
                {
                    return(BadRequest(AppResult.FailValidation(data: validationData)));
                }
                using (var trans = context.Database.BeginTransaction())
                {
                    var user = entity.User;
                    _service.DeleteMemberTransaction(entity);
                    var result = await _identityService.DeleteUserAsync(user);

                    if (!result.Succeeded)
                    {
                        foreach (var err in result.Errors)
                        {
                            ModelState.AddModelError(err.Code, err.Description);
                        }
                        var builder = ResultHelper.MakeInvalidAccountRegistrationResults(ModelState);
                        return(BadRequest(builder));
                    }
                    //log event
                    var ev = _sysService.GetEventForDeleteMember(
                        $"Admin has remove a user with email {entity.Email}",
                        UserId);
                    _sysService.CreateAppEvent(ev);
                    //end log event
                    context.SaveChanges();
                    trans.Commit();
                }
                return(NoContent());
            }
            catch (DbUpdateException e)
            {
                _logger.Error(e);
                return(BadRequest(AppResult.FailValidation(data: new ValidationData()
                                                           .Fail(code: AppResultCode.DependencyDeleteFail))));
            }
        }
        public IActionResult Update(int id, UpdateResourceModel model)
        {
            var entity = _service.Resources.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateResource(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            _service.UpdateResource(entity, model);
            context.SaveChanges();
            return(NoContent());
        }
        public async Task <IActionResult> RemoveRole(RemoveRolesFromUserModel model)
        {
            var entity = await _service.GetUserByUserNameAsync(model.username);

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var result = await _service.RemoveUserFromRolesAsync(entity, model.roles);

            if (result.Succeeded)
            {
                return(NoContent());
            }
            foreach (var err in result.Errors)
            {
                ModelState.AddModelError(err.Code, err.Description);
            }
            return(BadRequest(AppResult.FailValidation(ModelState)));
        }
        public IActionResult ChangeCurrentDeviceConfig(ChangeCurrentDeviceConfigModel model)
        {
            var entity = _service.DeviceConfigs.Id(model.ConfigId).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateChangeCurrentDeviceConfig(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var oldCurrent = _service.DeviceConfigs.IsCurrent().FirstOrDefault();

            _service.ChangeCurrentDeviceConfig(entity, oldCurrent);
            context.SaveChanges();
            Startup.SetCurrentConfig(entity);
            return(NoContent());
        }
        public async Task <IActionResult> Get([FromQuery][QueryObject] QCEventQueryFilter filter,
                                              [FromQuery] QCEventQuerySort sort,
                                              [FromQuery] QCEventQueryProjection projection,
                                              [FromQuery] QCEventQueryPaging paging,
                                              [FromQuery] QCEventQueryOptions options)
        {
            var validationData = _service.ValidateGetQCEvents(
                User, filter, sort, projection, paging, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var result = await _service.QueryQCEventDynamic(
                projection, options, Settings.Instance.QCEventImageFolderPath, filter, sort, paging);

            if (options.single_only && result == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            return(Ok(AppResult.Success(result)));
        }
        public IActionResult GetDetail(string code,
                                       [FromQuery] RoomQueryProjection projection,
                                       [FromQuery] RoomQueryOptions options,
                                       bool hanging = false)
        {
            var checkerValid = projection.GetFieldsArr().Contains(RoomQueryProjection.CHECKER_VALID);

            projection = new RoomQueryProjection {
                fields = RoomQueryProjection.DETAIL
            };
            var entity = _service.Rooms.Code(code).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateGetRoomDetail(entity, hanging, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            if (hanging)
            {
                _service.ReleaseHangingRoomByHangingUserId(UserId);
                _service.ChangeRoomHangingStatus(entity, true, UserId);
                context.SaveChanges();
            }
            var obj = _service.GetRoomDynamic(entity, projection, options);

            if (checkerValid)
            {
                var isRoomChecker = User.IsInRole(RoleName.ROOM_CHECKER);
                var valid         = _memberService.AreaMembers.OfArea(entity.BuildingAreaCode).Select(o => o.MemberId)
                                    .Contains(UserId) && isRoomChecker;
                obj["checker_valid"] = valid;
            }
            return(Ok(AppResult.Success(data: obj)));
        }
        public IActionResult Update(int id, UpdateDeviceConfigModel model)
        {
            var entity = _service.DeviceConfigs.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateDeviceConfig(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            _service.UpdateDeviceConfig(entity, model);
            context.SaveChanges();
            if (entity.IsCurrent)
            {
                Startup.SetCurrentConfig(entity);
            }
            return(NoContent());
        }
Пример #23
0
        public async Task <IActionResult> Get([FromQuery][QueryObject] DepartmentQueryFilter filter,
                                              [FromQuery] DepartmentQuerySort sort,
                                              [FromQuery] Business.Models.DepartmentQueryProjection projection,
                                              [FromQuery] DepartmentQueryPaging paging,
                                              [FromQuery] DepartmentQueryOptions options)
        {
            var validationData = _service.ValidateGetDepartments(
                filter, sort, projection, paging, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var result = await _service.QueryDepartmentDynamic(
                projection, validationData.TempData, filter, sort, paging, options);

            if (options.single_only && result == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            return(Ok(AppResult.Success(data: result)));
        }
        public IActionResult Update(int id, UpdateProductionBatchModel model)
        {
            var entity = _service.ProductionBatchs.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateProductionBatch(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            _service.UpdateProductionBatch(entity, model);
            context.SaveChanges();
            // must be in transaction
            var ev = _ev_service.UpdateProductionBatch(entity, User);

            context.SaveChanges();
            return(NoContent());
        }
        public async Task <IActionResult> Get([FromQuery][QueryObject] ProductionBatchQueryFilter filter,
                                              [FromQuery] ProductionBatchQuerySort sort,
                                              [FromQuery] ProductionBatchQueryProjection projection,
                                              [FromQuery] ProductionBatchQueryPaging paging,
                                              [FromQuery] ProductionBatchQueryOptions options)
        {
            var validationData = _service.ValidateGetProductionBatchs(
                User, filter, sort, projection, paging, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var result = await _service.QueryProductionBatchDynamic(
                projection, options, filter, sort, paging);

            if (options.single_only && result == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            return(Ok(AppResult.Success(result)));
        }
        public IActionResult ChangeStatus(int id, ChangeQCDeviceStatusModel model)
        {
            var entity = _service.QCDevices.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateChangeQCDeviceStatus(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            _service.ChangeQCDeviceStatus(entity, model);
            context.SaveChanges();
            // must be in transaction
            var ev = _ev_service.ChangeQCDeviceStatus(entity, User);

            context.SaveChanges();
            return(NoContent());
        }
        public async Task <IActionResult> GetRoomBookings([FromQuery][QueryObject] BookingQueryFilter filter,
                                                          [FromQuery] BookingQuerySort sort,
                                                          [FromQuery] BookingQueryProjection projection,
                                                          [FromQuery] BookingQueryPaging paging,
                                                          [FromQuery] BookingQueryOptions options)
        {
            var validationData = _service.ValidateGetRoomBookings(
                User, filter, sort, projection, paging, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var result = await _service.QueryBookingDynamic(
                User, member : null, relationship : null,
                projection, validationData.TempData, filter, sort, paging, options);

            if (options.single_only && result == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            return(Ok(AppResult.Success(data: result)));
        }
        public async Task <IActionResult> Update(string id, UpdateAppUserModel model)
        {
            var entity = _service.Users.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            var validationData = _service.ValidateUpdateAppUser(User, entity, model);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            _service.UpdateAppUser(entity, model);
            context.SaveChanges();
            var result = await _service.UpdatePasswordIfAvailable(entity, model);

            if (!result.Succeeded)
            {
                throw new Exception("Error change password");
            }
            return(NoContent());
        }
        public async Task <IActionResult> GetManagedRequests([FromQuery][QueryObject] BookingQueryFilter filter,
                                                             [FromQuery] BookingQuerySort sort,
                                                             [FromQuery] BookingQueryProjection projection,
                                                             [FromQuery] BookingQueryPaging paging,
                                                             [FromQuery] BookingQueryOptions options)
        {
            var validationData = _service.ValidateGetBookings(
                User, BookingPrincipalRelationship.Manager, filter, sort, projection, paging, options);

            if (!validationData.IsValid)
            {
                return(BadRequest(AppResult.FailValidation(data: validationData)));
            }
            var member = _memberService.Members.Id(UserId).FirstOrDefault();
            var result = await _service.QueryBookingDynamic(
                User, member, BookingPrincipalRelationship.Manager,
                projection, validationData.TempData, filter, sort, paging, options);

            if (options.single_only && result == null)
            {
                return(NotFound(AppResult.NotFound()));
            }
            return(Ok(AppResult.Success(data: result)));
        }
Пример #30
0
 public IActionResult Delete(string id)
 {
     try
     {
         var entity = _service.AppClients.Id(id).FirstOrDefault();
         if (entity == null)
         {
             return(NotFound(AppResult.NotFound()));
         }
         var validationData = _service.ValidateDeleteAppClient(User, entity);
         if (!validationData.IsValid)
         {
             return(BadRequest(AppResult.FailValidation(data: validationData)));
         }
         _service.DeleteAppClient(entity);
         context.SaveChanges();
         return(NoContent());
     }
     catch (DbUpdateException e)
     {
         _logger.Error(e);
         return(BadRequest(AppResult.DependencyDeleteFail()));
     }
 }