コード例 #1
0
        private async Task <ServiceResponseResult> UpdateDeviceStatus(long locationId, long id, long userId, ConfigStatusReqModel model)
        {
            var status = await _context.Devicestatus.FindAsync(id);

            if (status == null)
            {
                return(new ServiceResponseResult
                {
                    Result = new { Message = "Device status not found" },
                    StatusCode = System.Net.HttpStatusCode.NotFound
                });
            }

            status.Name          = model.Name;
            status.Description   = model.Description;
            status.IsDefault     = model.IsDefault;
            status.IsActive      = true;
            status.LastUpdatedBy = userId;
            status.LastUpdatedOn = DateTime.UtcNow;

            if (model.IsDefault)
            {
                await _context.Set <Devicestatus>().FromSqlRaw($"Update dbo.Devicestatus SET IsDefault = 0 OUTPUT INSERTED.* WHERE LocationId = {locationId} and id != {id}").ToListAsync();
            }

            _context.Devicestatus.Update(status);
            await _context.SaveChangesAsync();

            return(new ServiceResponseResult
            {
                Result = status == null ? null : new StatusDetailsResponseModel
                {
                    Id = status.Id,
                    Name = status.Name,
                    Description = status.Description,
                    IsActive = status.IsActive,
                    IsDefault = status.IsDefault
                },
                StatusCode = System.Net.HttpStatusCode.OK
            });
        }
コード例 #2
0
        public async Task <ServiceResponseResult> SearchAdmin(long locationId, long userId, AdminSearchReqModel model)
        {
            Logger.WriteInformation("Searching admin data.");
            model.Takes          = model.Takes == 0 || model.Takes > _appSettings.Limit ? _appSettings.Limit : model.Takes;
            model.OrderBy        = string.IsNullOrEmpty(model.OrderBy) ? "id" : model.OrderBy;
            model.OrderDirection = string.IsNullOrEmpty(model.OrderDirection) ? "desc" : model.OrderDirection;
            model.Name           = string.IsNullOrEmpty(model.Name) ? null : model.Name;
            model.Id             = string.IsNullOrEmpty(model.Id) ? null : model.Id;
            model.Email          = string.IsNullOrEmpty(model.Email) ? null : model.Email;

            var param = new SqlParameter[] { new SqlParameter("id", (object)model.Id ?? DBNull.Value)
                                             {
                                                 SqlDbType = SqlDbType.BigInt, Direction = ParameterDirection.Input, IsNullable = true,
                                             },
                                             new SqlParameter("onlyToolKitUser", (object)model.OnlyToolKitUser ?? DBNull.Value)
                                             {
                                                 SqlDbType = SqlDbType.Bit, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("name", (object)model.Name ?? DBNull.Value)
                                             {
                                                 SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("email", (object)model.Email ?? DBNull.Value)
                                             {
                                                 SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("state", (object)model.State ?? DBNull.Value)
                                             {
                                                 SqlDbType = SqlDbType.BigInt, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("statusid", (object)model.StatusId ?? DBNull.Value)
                                             {
                                                 SqlDbType = SqlDbType.BigInt, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("skip", model.Skips)
                                             {
                                                 SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("take", model.Takes)
                                             {
                                                 SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("orderby", model.OrderBy)
                                             {
                                                 SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, IsNullable = true
                                             },
                                             new SqlParameter("orderdir", model.OrderDirection)
                                             {
                                                 SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, IsNullable = true
                                             }, };

            var sql  = @"EXEC [dbo].[AdminSearch]";
            var data = await _context.Set <Administrator>().FromSqlRaw(sql, param).ToListAsync();

            var response = new AdministratorSearchResult
            {
                Items = data.Select(x =>
                {
                    var data = new AdministratorResult
                    {
                        DisabledReason = x.DisabledReason,
                        Email          = x.Email,
                        Id             = x.UserId,
                        Name           = x.Name,
                        Permissions    = new UserPermissionResult
                        {
                            HasAdminEdit     = x.HasAdminEdit.HasValue && x.HasAdminEdit.Value,
                            HasAdminRead     = x.HasAdminRead.HasValue && x.HasAdminRead.Value,
                            HasConfigEdit    = x.HasConfigEdit.HasValue && x.HasConfigEdit.Value,
                            HasConfigRead    = x.HasConfigRead.HasValue && x.HasConfigRead.Value,
                            HasDeviceEdit    = x.HasDeviceEdit.HasValue && x.HasDeviceEdit.Value,
                            HasDeviceRead    = x.HasDeviceRead.HasValue && x.HasDeviceRead.Value,
                            HasKeyholderEdit = x.HasKeyholderEdit.HasValue && x.HasKeyholderEdit.Value,
                            HasKeyholderRead = x.HasKeyholderRead.HasValue && x.HasKeyholderRead.Value,
                            HasSpaceEdit     = x.HasSpaceEdit.HasValue && x.HasSpaceEdit.Value,
                            HasSpaceRead     = x.HasSpaceRead.HasValue && x.HasSpaceRead.Value
                        },
                    };
                    if (x.State.HasValue)
                    {
                        data.State = Enum.Parse <AdministratorState>(x.State.Value.ToString());
                    }

                    if (x.UserActivityId.HasValue)
                    {
                        data.RecentActivity = new ActivityResult
                        {
                            ActivityText = x.ActivityText,
                            ActivityTime = x.ActivityTime,
                            Id           = x.UserActivityId.Value
                        };
                    }
                    if (x.StatusId.HasValue)
                    {
                        data.Status = new LookupEntityResult
                        {
                            Id   = x.StatusId.Value,
                            Name = x.StatusName
                        };
                    }
                    if (x.KeyHolderId.HasValue)
                    {
                        data.ToolkitInfo = new ToolkitInfoRespModel
                        {
                            Id = x.KeyHolderId.Value,
                            KeySerialNumber = x.KeySerialNumber,
                            Pin             = x.Pin
                        };
                    }
                    return(data);
                }).ToList(),
                TotalItems = data.Count()
            };

            Logger.WriteInformation("Searching admin data.");
            return(new ServiceResponseResult
            {
                Result = response,
                StatusCode = System.Net.HttpStatusCode.OK
            });
        }