Ejemplo n.º 1
0
 public ServiceHub()
 {
     orderRepository           = new Repositories.OrderRepository(db);
     productRepository         = new Repositories.ProductRepository(db);
     userRepository            = new Repositories.UserRepository(db);
     gameSettingsRepository    = new Repositories.GameSettingsRepository(db);
     serviceSettingsRepository = new Repositories.ServiceSettingRepositorie(db);
     localizationRepository    = new Repositories.LocalizationRepository(db);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public LocalizationController()
 {
     db = new DAL.ServiceContext();
     localizationRepository = new Repositories.LocalizationRepository(db);
 }