public virtual ActionResult Index(string id, QuizResultViewModel model) { var x = CurrentResource.CanUserTakeQuiz( CurrentUser, DateTime.UtcNow, Results.GetResults(CurrentResource, CurrentUser)); if (!x.Available) { return(View("Unavailable", x)); } // score the quiz var result = CurrentResource.Score(CurrentUser, model.Answers); // possibly award points if (result.Passed && result.PointsEarned.HasValue && result.PointsEarned > 0) { var tx = TryAwardPoints(result.PointsEarned.Value); if (null != tx) { result.Transaction = tx.Document.Id; } } Results.Save(result); // show the review screen return(RedirectToAction(MVC.Site.Quiz.Review(id, result.Document.Id))); }
public virtual ActionResult Index(string id, SurveyResultViewModel model) { var count = Results.GetResults(CurrentResource, CurrentUser).Count; if (CurrentResource.MaxTimes.HasValue && count > CurrentResource.MaxTimes) { return(View("Unavailable", AvailabilityResult.No("This survey can only be taken " + CurrentResource.MaxTimes + " times."))); } // score the Survey var result = CurrentResource.Score(CurrentUser, model.Answers); // possibly award points if (result.PointsEarned.HasValue && result.PointsEarned > 0) { var tx = TryAwardPoints(result.PointsEarned.Value); if (null != tx) { result.Transaction = tx.Document.Id; } } Results.Save(result); // show the review screen return(RedirectToAction(MVC.Site.Survey.Review(id, result.Document.Id))); }
/// <summary>Рисуем</summary> /// <param name="spriteBatch">The sprite batch.</param> public override void Draw(SpriteBatch spriteBatch) { //Здание Sprite.Draw(spriteBatch, Rect); //Подпись var health = CurrentResource.ToString() + "/" + MaxResource.ToString(); Vector2 FontOrigin = Font.MeasureString(health) / 2; var signatureRect = new Rectangle(Rect.X + Rect.Width / 2 - Signature.Width / 2, Rect.Y + Rect.Height - Signature.Height, Signature.Width, Signature.Height); Signature.Draw(spriteBatch, signatureRect); spriteBatch.DrawString(Font, health, new Vector2(signatureRect.Right - signatureRect.Width / 2, signatureRect.Bottom - signatureRect.Height / 2), Color.Black, 0, FontOrigin, 1, SpriteEffects.None, 1); //Кнопка апдейта if (Owner != null && Owner.Type == PlayerType.Human && _Level != _MaxLevel && !_StartUpdate) { spriteBatch.Draw(_Upgrade, new Vector2(Rect.X + 10, Rect.Y + 10)); } //Селекторы if (DrawEnemySelector) { spriteBatch.Draw(EnemySelector, Rect, Color.White); } else if (DrawOurSelector) { spriteBatch.Draw(OurSelector, Rect, Color.White); } }
private void BindLibrary() { if (CurrentResource != null && !CurrentResource.Match(resourceFilter)) { _currentResourceId = -1; } using (Database dbObj = new Database(SessionState.CacheComponents["DAM_DB"].ConnectionString)) { string sqlQuery = "SELECT * FROM VIEW_DAM_Resources WHERE LibraryId = @LibraryId{0} ORDER BY ResourceName"; sqlQuery = String.Format(sqlQuery, resourceFilter != null ? " AND (ResourceName LIKE '%' + @Filter+ '%' OR ResourceDescription LIKE '%' + @Filter+ '%')" : ""); using (DataSet ds = dbObj.RunSQLReturnDataSet(sqlQuery, Database.NewSqlParameter("@LibraryId", SqlDbType.Int, _currentLibraryId), Database.NewSqlParameter("@Filter", SqlDbType.NVarChar, 500, resourceFilter))) if (ds != null && ds.Tables.Count == 1) { resourcesPagerTop.Visible = resourcesPagerBottom.Visible = resourceGrid.Visible = completePanel.Visible = ds.Tables[0].Rows.Count > 0; resourceGrid.Columns[1].Visible = (DisplayMode != Mode.Complete); completePanel.Visible = completePanel.Visible && DisplayMode == Mode.Complete; resourceGrid.DataSource = ds; if (resourceGrid.CurrentPageIndex * resourceGrid.PageSize > ds.Tables[0].Rows.Count) { resourceGrid.CurrentPageIndex = 0; } if (_currentResourceId >= 0) { ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns[0] }; int index = ds.Tables[0].Rows.IndexOf(ds.Tables[0].Rows.Find(_currentResourceId)); resourceGrid.CurrentPageIndex = (int)Math.Floor((double)index / resourceGrid.PageSize); } resourceGrid.DataBind(); emptyLibPanel.Visible = ds.Tables[0].Rows.Count == 0; if (_currentResourceId < 0 && ds.Tables.Count == 1 && ds.Tables[0].Rows.Count > 0) { _currentResourceId = (int)ds.Tables[0].Rows[0]["ResourceId"]; chooseResource(0); } } } if (_currentResourceId >= 0) { //Response.Write(_currentResourceId + " " + resourceGrid.DataKeys.Count); for (int index = 0; index < resourceGrid.DataKeys.Count; index++) { if ((int)resourceGrid.DataKeys[index] == _currentResourceId) { chooseResource(index); } } } txtResourceTypeValue.DataSource = resourceTypes; resourceTypesAttributes.DataSource = resourceTypes; txtResourceTypeValue.DataBind(); resourceTypesAttributes.DataBind(); if (DisplayMode == Mode.Complete) { BindResource(); } }
public void LoadResource(int index) { if (index < 0 || index >= Resources.Count) { return; } var resource = Resources[index]; CurrentResource.Assign(resource); }
public virtual JsonResult Search(string id, string q) { return(Json( UserRepository .Search(q) .Where(x => x.Id != CurrentUser.Document.Id && CurrentResource.IsValidNominee(x)) .ToDictionary( x => x.Id, x => x.ToString()), JsonRequestBehavior.AllowGet )); }
public virtual ActionResult Index(string id) { var x = CurrentResource.CanUserTakeQuiz( CurrentUser, DateTime.UtcNow, Results.GetResults(CurrentResource, CurrentUser)); if (!x.Available) { return(View("Unavailable", x)); } return(View(QuizViewModel.FromDomain(CurrentResource))); }
public void StoreResource() { var resource = FindResource(CurrentResource.Offset); if (resource == null) { resource = CurrentResource.Clone(); resource.Name = string.Format("@{0:x8} ({0:d})", resource.Offset); Resources.Add(resource); } else { resource.Assign(CurrentResource); } }
private void BindLibrary() { if (CurrentResource != null && !CurrentResource.Match(resourceFilter)) { _currentResourceId = -1; } if (_currentResourceId < 0) { HyperCatalog.Business.DAM.Resource resource = resources.GetByIndex(0); if (resource != null) { _currentResourceId = resource.Id; } } rGd.DataSource = resources; rGd.DataBind(); rGd.Visible = completePanel.Visible = rGd.Rows.Count > 0; emptyLibPanel.Visible = rGd.Rows.Count == 0; if (_currentResourceId >= 0) { UltraGridRow row = null; for (int index = 0; index < rGd.DataKeys.Count; index++) { if ((int)rGd.DataKeys[index] == _currentResourceId) { row = rGd.Rows[index]; } } if (row != null) { row.Selected = true; } } txtResourceTypeValue.DataSource = resourceTypes; resourceTypesAttributes.DataSource = resourceTypes; txtResourceTypeValue.DataBind(); resourceTypesAttributes.DataBind(); if (DisplayMode == Mode.Complete) { BindResource(); } }
public bool AddResource(Resource Resource) { if (Resource.IsDepleted()) { return(false); } foreach (Resource CurrentResource in this.Resources) { if (CurrentResource.Add(Resource)) { return(true); } } this.Resources.Add(Resource); return(true); }
public virtual ActionResult Index(string id, GameResultViewModel model) { // score the Game var result = CurrentResource.Score(CurrentUser, model.Time, model.Score); // possibly award points if (result.PointsEarned.HasValue && result.PointsEarned > 0) { var tx = TryAwardPoints(result.PointsEarned.Value); if (null != tx) { result.Transaction = tx.Document.Id; } } Results.Save(result); // show the review screen return(Request.IsAjaxRequest() ? (ActionResult)Content(Url.Action(MVC.Site.Game.Review(id, result.Document.Id))) : RedirectToAction(MVC.Site.Game.Review(id, result.Document.Id))); }
public override void Draw(SpriteBatch spriteBatch) { //Здание Sprite.Draw(spriteBatch, Rect); //Подпись var health = CurrentResource.ToString() + "/" + MaxResource.ToString(); Vector2 FontOrigin = Font.MeasureString(health) / 2; var signatureRect = new Rectangle(Rect.X + Rect.Width / 2 - Signature.Width / 2, Rect.Y + Rect.Height - Signature.Height, Signature.Width, Signature.Height); Signature.Draw(spriteBatch, signatureRect); spriteBatch.DrawString(Font, health, new Vector2(signatureRect.Right - signatureRect.Width / 2, signatureRect.Bottom - signatureRect.Height / 2), Color.Black, 0, FontOrigin, 1, SpriteEffects.None, 1); //Селекторы if (DrawEnemySelector) { spriteBatch.Draw(EnemySelector, Rect, Color.White); } else if (DrawOurSelector) { spriteBatch.Draw(OurSelector, Rect, Color.White); } }
private void propertiesToolbar_ButtonClicked(object sender, ButtonEvent be) { switch (be.Button.Key) { #region case "CRT": case "CRT": if (CurrentResource != null && CurrentResource.Type.Name == "Template") { Response.Redirect(CurrentResource.URI + "?CRT=1"); // HyperCatalog.Business.DAM.Specific.HOTTemplate template = new HyperCatalog.Business.DAM.Specific.HOTTemplate(currentResource.MasterVariant.CurrentFile); // HyperComponents.IO.Streaming.SendStream(Response,template.CRTStream,currentResource.Name + ".pdf"); Response.End(); } break; #endregion #region case "Del": case "Del": if (SessionState.User.HasCapability(Business.CapabilitiesEnum.MANAGE_RESOURCES) && CurrentResource != null) { if (SessionState.User.IsReadOnly || CurrentResource.Delete()) { SetMessage(propertiesMsgLbl, "Resource \"" + CurrentResource.Name + "\" deleted", MessageLevel.Information); libraryList.SelectedItem.Text = String.Format(libraryListPattern, CurrentLibrary.Name, CurrentLibrary.ResourceCount); _currentResourceId = -1; BindLibrary(); } else { SetMessage(propertiesMsgLbl, "Resource \"" + CurrentResource.Name + "\" could not be deleted", MessageLevel.Error); } } break; #endregion #region case "Save": case "Save": if (txtFileBinaryValue.PostedFile.ContentLength > 0) { SetMessage(propertiesMsgLbl, "You must provide a file", MessageLevel.Warning); return; } if (SessionState.User.HasCapability(Business.CapabilitiesEnum.MANAGE_RESOURCES)) { if (SessionState.User.IsReadOnly) { return; } if (resourceTypesAttributes.Items.Count > txtResourceTypeValue.SelectedIndex) { if (txtResourceNameValue.Text == null || txtResourceNameValue.Text.Length == 0) { SetMessage(propertiesMsgLbl, "Resource must have a name", MessageLevel.Error); break; } string[][] attrs = getAttributeValues(resourceTypesAttributes.Items[txtResourceTypeValue.SelectedIndex]); if (CurrentResource != null) { CurrentResource.Name = txtResourceNameValue.Text; CurrentResource.Description = txtResourceDescriptionValue.Value; if (CurrentResource.Save()) { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" updated", MessageLevel.Information); if (addVariant) { bool success = false; string errorMsg = "Variant for \"" + txtResourceNameValue.Text + "\" could not be created"; try { success = CurrentResource.AddVariant(txtVariantCultureValue.SelectedValue, txtFileBinaryValue.PostedFile.InputStream, Path.GetExtension(txtFileBinaryValue.PostedFile.FileName), attrs) != null; } catch (AlreadyExistingVariantException) { errorMsg += ": this variant already exists."; } if (success) { SetMessage(propertiesMsgLbl, "Variant for \"" + txtResourceNameValue.Text + "\" created", MessageLevel.Information); } else { SetMessage(propertiesMsgLbl, errorMsg, MessageLevel.Error); } } BindLibrary(); } else { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" could not be updated", MessageLevel.Error); } } else { HyperCatalog.Business.DAM.Resource newResource = CurrentLibrary.AddResource(txtResourceNameValue.Text + Path.GetExtension(txtFileBinaryValue.PostedFile.FileName), txtResourceDescriptionValue.Value, Convert.ToInt32(txtResourceTypeValue.SelectedValue), txtVariantCultureValue.SelectedValue, txtFileBinaryValue.PostedFile.InputStream, attrs); if (newResource != null) { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" created", MessageLevel.Information); libraryList.SelectedItem.Text = String.Format(libraryListPattern, CurrentLibrary.Name, CurrentLibrary.ResourceCount); _currentResourceId = newResource.Id; BindLibrary(); } else { SetMessage(propertiesMsgLbl, "Resource \"" + txtResourceNameValue.Text + "\" could not be created", MessageLevel.Error); } } } } break; #endregion } }