public void ControlerCreateAward() { var httpRequest = new Mock <HttpRequestBase>(); httpRequest.SetupGet(req => req.Headers).Returns(new WebHeaderCollection { { "X-Requested-With", "XMLHttpRequest" } }); var httpContext = new Mock <HttpContextBase>(); httpContext.Setup(ctx => ctx.Request).Returns(httpRequest.Object); var awardModel = new AwardModel { Id = Guid.Parse("7816ec31-2185-4e0f-a32c-64d970eff009"), Title = "test", Description = "The test", ImageData = BaseHelper.GetImageData( "89-50-4E-47-0D-0A-1A-0A-00-00-00-0D-49-48-44-52-00-00-00-CF-00-00-00-D1-08-06-00-00-00-6B-5D-E6-B4-00-00-00-01-73-52-47-42-00-AE-CE-1C-E9-00-00-00-04-67-41-4D-41-00-00-B1-8F-0B-FC-61-05-00-00-00-09-70-48-59-73-00-00-0E-C2-00-00-0E-C2-01-15-28-4A-80-00-00-05-D6-49-44-41-54-78-5E-ED-DC-5B-72-DB-38-10-40-D1-68-16-90-FD-AF-33-1B-F0-04-35-62-D9-93-58-22-D9-7C-A0-1B-38-E7-27-FA-75-D0-57-0D-32-15-3F-3E-7E-FB-01-EC-F6-CF-F3-4F-60-27-F1-40-90-78-20-48-3C-10-24-1E-08-12-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-48-3C-10-24-1E-08-12-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-48-3C-10-24-1E-08-12-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-C8-EF-AA-BE-D9-E3-F1-78-7E-8A-71-5C-79-88-E7-02-47-03-89-72-94-F7-12-CF-09-7A-C5-B2-C6-D1-5E-4B-3C-01-59-63-59-E3-A8-CF-25-9E-8D-AA-06-F3-8A-63-3F-4E-3C-6F-5C-11-CC-C7-AF-E7-87-A0-C7-CF-E7-87-13-19-81-18-F1-7C-E3-68-34-47-03-89-3A-23-2C-E3-B0-9D-78-9E-8E-04-D3-2B-96-35-47-62-32-16-EB-A6-8F-27-1A-4D-D6-60-DE-89-C4-24-A2-D7-A6-8D-27-12-4D-C5-60-BE-23-A2-73-4C-19-CF-9E-70-46-09-E6-95-3D-21-09-E8-FF-A6-8A-47-34-AF-89-68-BF-29-E2-11-CD-76-22-DA-6E-F8-78-B6-84-33-7B-30-AF-6C-09-69-E6-80-86-8D-67-EB-B6-11-CE-7B-5B-37-D1-8C-11-0D-19-8F-6D-73-3E-5B-E8-6F-C3-C5-B3-16-8E-68-8E-59-8B-68-A6-80-86-89-C7-B6-B9-8F-2D-F4-9F-21-E2-B1-6D-FA-98-7D-0B-95-FF-1D-06-C2-E9-67-ED-EF-76-CB-6D-A0-B2-D2-F1-08-A7-BF-99-03-2A-7B-6D-7B-77-28-A2-E9-E3-DD-35-6E-C4-2B-5C-C9-CD-23-9C-9C-DE-FD-DD-8F-B8-81-CA-C5-23-9C-DC-66-0A-A8-54-3C-C2-A9-61-96-80-CA-C4-23-9C-5A-66-08-A8-44-3C-C2-A9-69-F4-80-D2-C7-23-9C-DA-46-0E-28-75-3C-C2-19-C3-A8-01-A5-8D-47-38-63-19-31-A0-32-2F-0C-16-C2-A9-6B-B4-B3-4B-19-CF-AB-6F-22-E1-D4-F7-EA-0C-2B-6E-9F-74-F1-08-67-7C-A3-04-94-2A-9E-AA-77-5F-CE-53-69-06-4A-3C-F3-D8-3A-E3-19-E1-4C-D3-C4-E3-BA-36-9F-EA-D7-B7-D4-9B-47-38-E3-AB-1C-50-8A-78-3C-EB-50-51-F7-78-5C-D7-A8-BA-7D-4A-BC-30-60-7C-15-BF-2C-BB-C6-63-EB-B0-26-F3-F6-49-B7-79-84-33-AF-6A-67-DF-2D-1E-2F-09-D8-2A-EB-AC-A4-DA-3C-B6-0E-95-66-A0-4B-3C-B6-0E-7B-65-9C-99-34-9B-C7-D6-61-51-65-16-6E-8F-C7-D6-21-2A-DB-EC-A4-D8-3C-B6-0E-7F-AA-30-13-B7-C6-63-EB-70-54-A6-19-EA-BE-79-6C-1D-5E-C9-3E-1B-69-5E-18-40-35-B7-C5-E3-CA-C6-59-B2-CC-52-D7-CD-E3-CA-C6-9A-CC-33-E2-DA-46-49-19-B6-CF-2D-F1-7C-F7-83-DA-3A-6C-95-75-56-6C-1E-08-12-0F-04-5D-1E-8F-B7-6C-5C-A5-F7-6C-75-D9-3C-9E-77-D8-2B-E3-CC-B8-B6-41-90-78-20-48-3C-94-D6-F3-B9-E7-D2-78-FC-FB-0E-67-CA-36-3B-36-0F-04-89-07-82-C4-03-41-E2-81-20-F1-50-5E-AF-37-6E-97-C5-E3-4D-1B-57-C8-34-43-36-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-48-3C-10-24-1E-08-12-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-48-3C-10-74-59-3C-1F-1F-1F-CF-4F-9F-1E-3F-9F-1F-20-E8-BB-19-FA-6E-D6-EE-60-F3-40-90-78-20-48-3C-10-24-1E-08-12-0F-04-5D-1A-8F-37-6E-9C-29-DB-EC-D8-3C-94-D6-EB-35-75-23-1E-08-12-0F-04-75-89-C7-73-0F-7B-65-9C-99-CB-E3-E9-79-27-65-6C-BD-67-CB-B5-0D-82-C4-03-41-DD-E2-F1-DC-C3-56-59-67-E5-96-78-3C-F7-70-B6-0C-33-D5-F5-DA-66-FB-50-D9-6D-F1-D8-3E-44-7C-F7-05-9B-65-96-BC-30-80-A0-EE-F1-B8-BA-F1-4A-F6-D9-B8-35-1E-57-37-8E-CA-34-43-29-AE-6D-B6-0F-7F-AA-30-13-B7-C7-63-FB-10-95-6D-76-D2-BC-30-B0-7D-58-54-99-85-2E-F1-D8-3E-EC-95-71-66-D2-6C-9E-C6-F6-A1-D2-0C-74-8B-C7-F6-61-AB-AC-B3-92-6A-F3-34-B6-CF-BC-AA-9D-7D-D7-78-6C-1F-D6-64-9E-91-74-9B-A7-B1-7D-E6-53-F1-CC-BB-C7-F3-EA-9B-45-40-F3-78-75-D6-D9-6F-26-29-37-0F-54-90-22-1E-DB-67-5E-55-B7-4E-93-66-F3-08-68-3E-95-C3-69-4A-5C-DB-04-34-9E-11-CE-34-55-3C-55-BE-71-B8-4E-A5-19-48-B7-79-5C-DF-C6-57-FD-BA-B6-48-79-6D-13-D0-B8-46-09-A7-29-F1-CC-F3-95-80-EA-1A-ED-EC-D2-C6-F3-EE-9B-48-40-F5-BC-3B-B3-8A-5B-A7-49-BD-79-04-34-86-11-C3-69-D2-5F-DB-04-54-DB-A8-E1-34-25-9E-79-04-54-D3-C8-E1-34-65-5E-18-08-A8-96-D1-C3-69-CA-C4-D3-08-A8-86-19-C2-69-4A-C5-D3-08-28-B7-59-C2-69-CA-C5-D3-08-28-A7-99-C2-69-1E-BF-7F-A8-B2-3F-D5-E3-F1-78-7E-FA-DE-C7-AF-E7-07-2E-37-5B-38-4D-E9-78-1A-01-F5-B5-B6-E9-47-0D-A7-29-79-6D-FB-6A-ED-70-5C-E3-AE-33-73-38-4D-F9-CD-B3-58-DB-40-8D-2D-74-8E-2D-5F-48-A3-87-D3-94-DF-3C-8B-76-58-6B-07-66-0B-1D-27-9C-4F-C3-6C-9E-AF-6C-A1-F3-89-E6-6F-43-C6-D3-6C-09-A8-11-D1-7B-5B-B7-F5-6C-E1-34-C3-C6-B3-B0-85-E2-6C-9B-F7-86-8F-A7-B1-85-F6-B1-6D-B6-99-22-9E-C5-D6-88-9A-D9-42-DA-1A-4C-33-7B-34-8B-A9-E2-59-88-E8-D3-9E-68-1A-E1-7C-9A-32-9E-66-4F-40-CD-68-11-89-E6-B8-69-E3-59-EC-8D-A8-A9-1A-D2-DE-60-1A-D1-BC-36-7D-3C-8B-48-44-8B-AC-31-45-62-59-18-8B-75-E2-F9-C3-91-88-16-BD-62-3A-12-CB-C2-38-6C-27-9E-37-CE-08-E9-AB-B3-A2-3A-23-92-AF-8C-40-8C-78-36-3A-3B-A4-DE-1C-FB-71-E2-09-A8-1C-92-E3-3E-8F-78-0E-CA-1E-92-E3-BD-8E-78-4E-D6-33-26-47-79-2F-F1-DC-E8-AC-B0-1C-59-0E-E2-81-A0-61-FE-27-29-DC-4D-3C-10-24-1E-08-12-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-48-3C-10-24-1E-08-12-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-48-3C-10-24-1E-08-12-0F-04-89-07-82-C4-03-41-E2-81-20-F1-40-90-78-20-48-3C-10-24-1E-08-12-0F-84-FC-F8-F1-2F-3A-03-62-F1-18-1D-ED-01-00-00-00-00-49-45-4E-44-AE-42-60-82"), ImageMimeType = "image/png" }; var cntBefore = AwardHelper.AwardModelList.Count; var controller = new AwardController(); var result = controller.Create(model: awardModel); var cntAfter = AwardHelper.AwardModelList.Count; Assert.AreEqual(cntBefore + 1, cntAfter, "Error in controller create award..."); }
public ActionResult Create(AwardModel model, HttpPostedFileBase image = null) { try { if (image != null) { model.ImageMimeType = image.ContentType; model.ImageData = new byte[image.ContentLength]; image.InputStream.Read(model.ImageData, 0, image.ContentLength); ModelState.Remove("ImageData"); ModelState.Add("ImageData", new ModelState()); ModelState.SetModelValue("ImageData", new ValueProviderResult(new byte[image.ContentLength], "1", null)); } if (!ModelState.IsValid) { return(View()); } AwardHelper.CreateEntity(model); return(RedirectToAction("Index")); } catch { return(View()); } }
/*public void DeleteAward(int id) * { * foreach (AwardModel award in awardsList) * { * if (award.Id == id) * { * awardsList.Remove(award); * break; * } * } * }*/ // PUT : api/Award/5 public IHttpActionResult PutAward(int id, AwardModel awardModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != awardModel.Id) { return(BadRequest()); } var award = Mapper.Map <Award>(awardModel); db.Entry(award).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AwardExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult PostAward([FromBody] AwardModel awardModel) { _logger.LogInformation($"{nameof(AwardController)} : {nameof(PostAward)} was called."); try { if (awardModel == null) { return(BadRequest("Award is required")); } if (_awardService.FindById(awardModel.Id) != null) { return(Conflict("Award already exists")); } _awardService.Create(awardModel); _awardService.Save(); return(Ok(awardModel)); } catch (DbException exception) { _logger.LogError(exception.Message); return(BadRequest(exception.Message)); } catch (Exception exception) { _logger.LogError(exception.Message); throw; } }
public IActionResult UpdateAward([FromBody] AwardModel awardModel) { _logger.LogInformation($"{nameof(AwardController)} : {nameof(UpdateAward)} was called."); try { if (awardModel == null) { return(BadRequest("Award is required")); } if (_awardService.FindById(awardModel.Id) == null) { return(NotFound("Award not found")); } _awardService.Update(awardModel); _awardService.Save(); return(Ok()); } catch (DbException exception) { _logger.LogError(exception.Message); return(BadRequest(exception.Message)); } catch (Exception exception) { _logger.LogError(exception.Message); throw; } }
public ActionResult EditActivityConfig(string id = "") { var textPath = Server.MapPath("~") + "Areas\\Activity\\ActivityConfiguration.txt"; var configContent = TextProcessHelper.GetTextLines(textPath); var awardModelList = new List <AwardModel>(); foreach (var content in configContent) { var award = new AwardModel(); if (!content.StartsWith("id")) { var line = content.Split(','); award.AwardId = line[0]; award.RatioBegain = line[1]; award.RatioEnd = line[2]; award.AwardMessage = line[3]; award.IsAward = bool.Parse(line[4]); awardModelList.Add(award); } } var awardModel = new AwardModel(); if (!string.IsNullOrEmpty(id)) { awardModel = awardModelList.Where(o => o.AwardId == id).FirstOrDefault(); } return(View("EditAwardConfig", awardModel)); }
public ActionResult EditActivityConfig(AwardModel award) { int count = 0; var IsNewAward = true; var newLine = award.AwardId + "," + award.RatioBegain + "," + award.RatioEnd + "," + award.AwardMessage + "," + (award.IsAward ? "true" : "false"); var textPath = Server.MapPath("~") + "Areas\\Activity\\ActivityConfiguration.txt"; var configContent = TextProcessHelper.GetTextLines(textPath); var newConfigContent = new List <string>(); foreach (var content in configContent) { count++; if (content.StartsWith(award.AwardId)) { newConfigContent.Add(newLine); IsNewAward = false; } else { newConfigContent.Add(content); if (count == configContent.Count && IsNewAward) { newConfigContent.Add(newLine); } } } if (!configContent.Any()) { newConfigContent.Add(newLine); } TextProcessHelper.WriteText(textPath, newConfigContent); return(RedirectToAction("ActivityGetAwardConfigGet")); }
public ActionResult Edit(int awardID) { AwardModel awardModel = new AwardModel(); //awardModel = _gameTeamPlayerModelSelect.GetGameTeamPlayerModel(awardID); return(View(awardModel)); }
public async Task <ActionResult> Delete(int awardID) { AwardModel awardModel = new AwardModel(); awardModel = await _awardModelSelect.GetAwardModel(awardID); return(View(awardModel)); }
public void Update(AwardModel entity) { var index = _awardModels.FindIndex(a => a.Id == entity.Id); if (index > 0) { _awardModels[index] = entity; } }
public ActionResult EditAward(AwardModel model) { ViewBag.Message = "EditAward"; if (ModelState.IsValid) { awardLogic.UpdateAwardTitle(model.ID, model.Title); return(RedirectToAction("Index")); } return(View()); }
public ActionResult AddAward(AwardModel model) { ViewBag.Message = "AddAward"; if (ModelState.IsValid) { awardLogic.AddAward(model.Title, new List <int>()); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Create(AwardModel creationModel) { if (ModelState.IsValid) { var createdAward = new Award(creationModel.Title); awardLogic.Create(createdAward); return(RedirectToAction("GetList")); } return(View(creationModel)); }
internal Award ConvertToAward(AwardModel awardModel) { Award award = new Award(); award.ActiveInd = awardModel.ActiveInd; award.AwardID = awardModel.AwardID; award.AwardName = awardModel.AwardName; award.Comments = awardModel.Comments; return(award); }
internal AwardModel ConvertToAwardModel(Award award) { AwardModel awardModel = new AwardModel(); awardModel.ActiveInd = award.ActiveInd ?? true; awardModel.AwardID = award.AwardID; awardModel.AwardName = award.AwardName; awardModel.Comments = award.Comments; return(awardModel); }
public ActionResult Delete(AwardModel model) { try { AwardHelper.DeleteEntity(model.Id); return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// The created new AwardModel entity. /// </summary> /// <param name="newModel">The AwardModel.</param> public static void UpdateEntity(AwardModel newModel) { var awardModel = GetAwardModelEntity(newModel.Id); if (awardModel != null) { awardModel.Title = newModel.Title; awardModel.Description = newModel.Description; awardModel.ImageData = newModel.ImageData; awardModel.ImageMimeType = newModel.ImageMimeType; } }
public void Update(AwardModel model) { var award = GetAwardById(model.Id); award.Name = model.Name; award.Year = model.Year; award.GameId = model.GameId; db.Awards.Update(award); db.SaveChanges(); }
public HttpResponseMessage Post(AwardModel awardModel) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse( HttpStatusCode.BadRequest, new HttpError(ModelState.FirstError()))); } var award = awardModel.ToEntity <Award>(); return(SaveChanges(award, x => _awardService.Insert(x), _resourceManager.GetString("Award.FailedToCreate"))); }
public void PostAward_WhenCalled_ReturnsOkResult() { // Arrange var award = new AwardModel { Id = 4 }; // Act var result = _controller.PostAward(award); // Assert Assert.IsType <OkObjectResult>(result); }
public void UpdateAward_WhenCalledIncorrectly_ReturnsBadResult() { // Arrange var award = new AwardModel { Id = -1 }; // Act var result = _controller.UpdateAward(award); // Assert Assert.IsType <NotFoundObjectResult>(result); }
public ActionResult Delete(int id) { try { var award = awardLogic.Get(id); var awardModel = new AwardModel(award.Title, award.Id); return(View(awardModel)); } catch (KeyNotFoundException) { return(HttpNotFound()); } }
internal List <AwardModel> AwardListToAwardModelListConvert(IList <Award> awardList) { List <AwardModel> awardModelList = new List <AwardModel>(); AwardToAwardModelConverter awardToAwardModelConverter = new AwardToAwardModelConverter(); foreach (Award award in awardList) { AwardModel awardModel = new AwardModel(); awardModel = awardToAwardModelConverter.ConvertToAwardModel(award); awardModelList.Add(awardModel); } return(awardModelList); }
public static AwardEntity ToEntity(AwardModel awardModel) { if (awardModel == null) { return(null); } return(new AwardEntity { Description = awardModel.Description, Id = awardModel.Id, Name = awardModel.Name, ReceivedDate = awardModel.ReceivedDate }); }
// POST: api/Awards public IHttpActionResult PostAward(AwardModel awardModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var award = Mapper.Map <Award>(awardModel); db.Awards.Add(award); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = award.Id }, award)); }
public void AwardModelValidationTest(string description, int position, AwardType type, bool expectedResult) { var awardModel = new AwardModel { Description = description, Position = position, Type = type }; var validation = new AwardModelValidation(); var result = validation.Validate(awardModel); Assert.IsTrue(result.IsValid == expectedResult); }
public static Award ModelToDomain(this AwardModel award) { if (award == null) { return(null); } return(new Award { Id = award.Id, Title = award.Title, UsersAwarded = new List <Guid>() }); }
public string DisplayUsersAwarded(AwardModel award) { var awardDomain = _awardsService.GetAwardById(award.Id); StringBuilder s = new StringBuilder(); if (awardDomain.UsersAwarded == null) { return("No user has received this award."); } foreach (var userId in awardDomain.UsersAwarded) { var user = _usersService.GetUserById(userId); s.Append(user.Name + " "); } return(s.ToString()); }
public ActionResult Edit(AwardModel model, HttpPostedFileBase image = null) { try { if (image != null) { model.ImageMimeType = image.ContentType; model.ImageData = new byte[image.ContentLength]; image.InputStream.Read(model.ImageData, 0, image.ContentLength); } AwardHelper.UpdateEntity(model); return(RedirectToAction("Index")); } catch { return(View()); } }
public TitleDetailsModel GetTitleDetails(string id) { var titleID = Convert.ToInt32(id); var repo = new TitlesEntities(); var titles = _titlesRepo.Titles.Where(x => x.TitleId == titleID).FirstOrDefault(); var awards = titles.Awards.Where(x => x.AwardWon == true).OrderByDescending(x => x.AwardYear).ToList(); var nominations = titles.Awards.Where(x => x.AwardWon == false).OrderByDescending(x => x.AwardYear).ToList(); var awardsList = new List <AwardModel>(); foreach (var award in awards) { AwardModel am = new AwardModel(); am.Award = award.Award1; am.AwardCompany = award.AwardCompany; am.AwardYear = award.AwardYear.ToString(); awardsList.Add(am); } var nominationsList = new List <AwardModel>(); foreach (var nomination in nominations) { AwardModel am = new AwardModel(); am.Award = nomination.Award1; am.AwardCompany = nomination.AwardCompany; am.AwardYear = nomination.AwardYear.ToString(); nominationsList.Add(am); } TitleDetailsModel tdm = new TitleDetailsModel(); tdm.ReleaseYear = titles.ReleaseYear.ToString(); tdm.TitleName = titles.TitleName; tdm.Genres = titles.TitleGenres.Select(x => x.Genre.Name).ToList(); tdm.Description = titles.StoryLines.FirstOrDefault().Description; tdm.Participants = titles.TitleParticipants.Select(x => x.Participant.Name).ToList(); tdm.Awards = awardsList; tdm.Nominations = nominationsList; return(tdm); }