コード例 #1
0
ファイル: ServiceHub.cs プロジェクト: womd/SignalRService
        private DTOs.GeneralHubResponseObject _updateLocalizationProperty(string PropertyName, string Content, string Culture)
        {
            if (localizationRepository.Exists(PropertyName, Culture))
            {
                var dbItem = localizationRepository.Get(PropertyName, Culture);
                dbItem.Value = Content;
                localizationRepository.Update(dbItem, Context.Request.User.Identity.Name);

                Localization.UiResources.Instance.removeFromCache(dbItem.Key, dbItem.Culture);
                return(new DTOs.GeneralHubResponseObject()
                {
                    Success = true,
                    Message = "Data sucessfuly saved."
                });
            }
            else
            {
                return(new DTOs.GeneralHubResponseObject()
                {
                    Success = false,
                    ErrorMessage = "Property " + PropertyName + " does not exist..."
                });
            }
        }
コード例 #2
0
        public DTOs.GeneralHubResponseObject ProcessIncoming(DTOs.GeneralHubRequestObject Request)
        {
            GeneralHubResponseObject result = new GeneralHubResponseObject();

            var jconf     = JsonConvert.SerializeObject(Request.RequestData);
            var mrRequest = JsonConvert.DeserializeObject <MiningRoomRequesObject>(jconf);


            switch (mrRequest.Command)
            {
            case "GetRoomOverview":
                var overviewData = GetOverview(mrRequest.MiningRoomId);
                result.Success      = true;
                result.ResponseData = overviewData;
                break;


            case "ToggleControls":
                var dbMiningRoomx = db.MiningRooms.FirstOrDefault(ln => ln.Id == mrRequest.MiningRoomId);
                if (dbMiningRoomx.ServiceSetting.Owner == Request.User || Request.User.IsInRole("Admin"))
                {
                    bool isOn = bool.Parse(mrRequest.CommandData.ToString());
                    dbMiningRoomx.ShowControls = isOn;
                    db.SaveChanges();

                    var vm = GetOverview(mrRequest.MiningRoomId);
                    SendRoomInfoUpdateToClients(vm, dbMiningRoomx.ServiceSetting.ServiceUrl.ToLower());
                }
                break;

            case "CreateRoom":

                result = CreateMiningRoom(Request.User, mrRequest);
                break;

            case "UpdateDescription":
                if (!Request.User.Identity.IsAuthenticated)
                {
                    result.Success      = false;
                    result.ErrorMessage = SignalRService.Localization.BaseResource.Get("MsgLoginFirst");
                    break;
                }

                var dbRoom = db.MiningRooms.FirstOrDefault(ln => ln.Id == mrRequest.MiningRoomId);
                if (dbRoom == null)
                {
                    result.Success      = false;
                    result.ErrorMessage = "Invalid RoomId";
                }

                if (!Utils.ServiceUtils.IsServiceOwner(dbRoom.ServiceSetting.ID, Request.User.Identity.Name))
                {
                    if (!Request.User.IsInRole("Admin"))
                    {
                        result.Success      = false;
                        result.ErrorMessage = "No Permission";
                        break;
                    }
                }

                string contentData = ((dynamic)mrRequest.CommandData).Content;
                string cultureName = ((dynamic)mrRequest.CommandData).Culture;

                var localizationKey = GetDescriptionKeyForRoom(dbRoom.Id);
                Repositories.LocalizationRepository localizationRepo = new Repositories.LocalizationRepository(db);
                if (localizationRepo.Exists(localizationKey, cultureName))
                {
                    var dbItem = localizationRepo.Get(localizationKey, cultureName);
                    dbItem.Value = contentData;
                    localizationRepo.Update(dbItem, Request.User.Identity.Name);

                    Localization.UiResources.Instance.removeFromCache(localizationKey, cultureName);

                    result.Success = true;
                    result.Message = "description updated successfuly";
                }
                else
                {
                    localizationRepo.Create(new Models.LocalizationModel()
                    {
                        CreationDate      = DateTime.Now,
                        Archived          = false,
                        Culture           = cultureName,
                        Key               = localizationKey,
                        LastModDate       = DateTime.Now,
                        ModUser           = Request.User.Identity.Name,
                        TranslationStatus = Enums.EnumTranslationStatus.Undefined,
                        Value             = contentData,
                        WasHit            = false
                    }, Request.User.Identity.Name);

                    result.Success = true;
                    result.Message = "creating localizationItem success.";
                }

                break;

            default:
                break;
            }

            return(result);
        }