public ActionResult UploadExcel(HttpPostedFileBase file) { string line; string[] arrayLine; if (file.ContentLength > 0) { if (file.ContentType == "application/vnd.ms-excel") { string filename = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1); string filePath = HttpContext.Server.MapPath("/content/" + filename); file.SaveAs(filePath); using (StreamReader streamReader = new StreamReader(filePath)) { while ((line = streamReader.ReadLine()) != null) { var wish = new Wish(); arrayLine = line.Split(new char[] { ',' }); //姓名 wish.Name = arrayLine[2]; //许愿人介绍 wish.Description = arrayLine[6]; //浏览 wish.Count = 0; //日期 wish.DateStart = DateTime.Now; //寄语 //wish.Hope = arrayLine[4]; wish.Title = arrayLine[6]; wish.Status = 0; wish.PictureFile = ""; wish.Support = 0; wish.UserID = 1; wish.WishDescription = arrayLine[9]; new WishHelper().AddWish(wish); //siteService.Save(); //string a = arrayLine[9]; //if (a == "1") //{ // wish.IsApply = true; // var apply = new Apply(); // apply.ContactName = arrayLine[10]; // apply.ContactAddress = arrayLine[11]; // apply.ContactTel = arrayLine[12]; // apply.WishID = wish.WishID; // siteService.InsertApply(apply); //} //siteService.Save(); } } } } return(View()); }
public BaseObject AddWish(Wish wish) { var obj = new BaseObject(); try { if (db.Wishes.Any(m => m.Title.Contains(wish.Title))) { obj.Tag = -2; obj.Message = "标题已存在!"; return(obj); } wish.Status = WishStatus.WaitAudit; wish.DateStart = DateTime.Now; wish.ApplyUserID = 0; db.Wishes.Add(wish); db.SaveChanges(); obj.Tag = 1; var user = db.Users.FirstOrDefault(m => m.ID == wish.UserID); user.Heart += 1; db.SaveChanges(); } catch (Exception e) { obj.Tag = -1; obj.Message = e.Message; } return(obj); }
public void Updating_Wish_Will_Update_ChangeDate() { //Create a wish to work with Wish wish = new Wish() { Name = "Update test wish", Description = "The test description", LinkUrl = "http://notupdated.yet", Owner = new User() { Id = firstUserId }, CalledByUser = null }; wish = rep.SaveWish(wish); DateTime lastChanged = wish.Changed.Value; Thread.Sleep(20); rep.SaveWish(wish); var updatedWish = rep.GetWishes().WithId(wish.Id); Assert.IsTrue(updatedWish.Changed > lastChanged, "Change date was not updated on save"); }
public void Calling_Wish_Will_Not_Update_ChangeDate() { //Create a wish to work with Wish wish = new Wish() { Name = "Update test wish", Description = "The test description", LinkUrl = "http://notupdated.yet", Owner = new User() { Id = firstUserId }, CalledByUser = null }; wish = rep.SaveWish(wish); DateTime lastChanged = wish.Changed.Value; wish.CalledByUser = new User { Id = firstUserId }; rep.SaveWish(wish); var updatedWish = rep.GetWishes().WithId(wish.Id); Assert.IsTrue(lastChanged.IsAlmostEqualTo(updatedWish.Changed.Value), "Calling a wish updated the change date"); }
public void SqlRepository_Can_Remove_Wish() { //First we add the wish we want to remove later. Wish wish = new Wish { Name = "Removetest wish", Description = "Description of wish", Owner = new User() { Id = firstUserId }, CalledByUser = new User() { Id = secondUserId }, LinkUrl = "http://localhost" }; int numberOfWishes = rep.GetWishes().Count <Wish>(); Wish savedWish = rep.SaveWish(wish); Assert.AreEqual <int>(numberOfWishes + 1, rep.GetWishes().Count()); rep.RemoveWish(savedWish); Assert.AreEqual <int>(numberOfWishes, rep.GetWishes().Count(), "Number of wishes in repository did not decrease"); var loadedWish = (from w in dataContext.Wishes where w.WishId == savedWish.Id select w).SingleOrDefault(); Assert.IsNull(loadedWish, "Removed wish was still found in repository"); }
public void SqlRepository_Can_Update_Wish() { //Create a wish to work with Wish wish = new Wish() { Name = "Update test wish", Description = "The test description", LinkUrl = "http://notupdated.yet", Owner = new User() { Id = firstUserId }, CalledByUser = null }; Wish wishToUpdate = rep.SaveWish(wish); //Do the update wishToUpdate.Name = "Updated test wish"; wishToUpdate.Description = "Updated description"; wishToUpdate.LinkUrl = "http://isupdated.now"; wishToUpdate.CalledByUser = new User() { Id = secondUserId }; Wish updatedWish = rep.SaveWish(wishToUpdate); Assert.IsNotNull(updatedWish, "Updated wish could not be loaded"); Assert.AreEqual <string>(wishToUpdate.Name, updatedWish.Name, "Name was not updated correctly"); Assert.AreEqual <string>(wishToUpdate.Description, updatedWish.Description, "Description was not updated correctly"); Assert.AreEqual <string>(wishToUpdate.LinkUrl, updatedWish.LinkUrl, "LinkUrl was not updated correctly"); Assert.AreEqual <int?>(wishToUpdate.CalledByUser.Id, updatedWish.CalledByUser.Id, "CalledByUser was not updated correctly"); Assert.AreEqual(wishToUpdate.Created, updatedWish.Created, "Creation time changed while updating!"); }
public bool UseWish(Wish wish) {//broken // Debug.Log("Using wish!!! " + wish.type + "\n"); for (int i = 1; i < wishes.Count; i++) { if (wishes[i].my_wish.type == wish.type && wishes[i].my_wish.strength == wish.strength) { // Debug.Log("Using wish " + i + "\n"); if (DoTheThing(wishes[i].my_wish)) { return(SubtractWish(wishes[i].my_wish.type, 1)); /* * MyWishButton b = (MyWishButton)wishes[i].my_label.ui_button; * int count = wishes[i].my_wish.Count; * if (count > 1) * { * wishes[i].my_wish.Count--; * b.setCount(-1, false); * } * else * { * _removeWishLabel(i); * wishes.RemoveAt(i); * } * * return true;*/ } return(false); } } //Debug.Log("Could not locate wish " + wish.type + " strength " + wish.strength + " to remove, trying to remove an invalid wish!!!!\n"); return(false); }
public void SqlRepository_Can_Add_Wish() { Wish wish = new Wish { Name = "Addtest wish", Description = "Description of wish", Owner = new User() { Id = firstUserId }, CalledByUser = new User() { Id = secondUserId }, LinkUrl = "http://localhost" }; rep.SaveWish(wish); var loadedWishes = (from w in dataContext.Wishes where w.Name == wish.Name select w).ToList(); Assert.IsTrue(loadedWishes.Count == 1, "Did not contain 1 wish"); Assert.AreEqual(loadedWishes[0].Name, wish.Name, "Wish name was not correct"); Assert.AreEqual(loadedWishes[0].Description, wish.Description, "Wish description was not correct"); Assert.AreEqual(loadedWishes[0].OwnerId, wish.Owner.Id, "Wish ownerid was not correct"); Assert.AreEqual(loadedWishes[0].TjingedById, wish.CalledByUser.Id, "Wish tjingedbyid was not correct"); Assert.AreEqual(loadedWishes[0].LinkUrl, wish.LinkUrl, "Wish linkurl was not correct"); Assert.AreEqual(loadedWishes[0].Created, loadedWishes[0].Changed, "Change time was not equal to created time"); }
// GET: Wishes/Details/5 public ActionResult Details(int id) { Wish wish = service.GetById(id); if (wish == null) { return(HttpNotFound()); } //getting to percentage of the fund raised to show it in the progress bar double FundRaisedPercentage = ((double)wish.FundRaised / wish.FundToRaise) * 100; ViewBag.ProgressFund = FundRaisedPercentage; Kid kid = wish.Kid; ViewBag.expirationDays = (wish.ExpirationDate - DateTime.Now).Days; if (kid.RelationshipToChild == Referer.Relative) { ViewBag.fundraiser = "My " + kid.RelationSpecification; } else { ViewBag.fundraiser = "The Organisation" + kid.OrganizationName; } return(View(wish)); }
public void WishList_Can_Add_Wish_For_User() { int ownerId = 1; WishList.Data.WishList list = Service.GetWishList(ownerId); int numberOfWishes = list.Wishes.Count; Wish newWish = new Wish() { Owner = new User() { Id = ownerId }, Name = "Testönskning", Description = "Lorem ipsum dolor sit amet" }; Service.SaveWish(newWish, true); list = Service.GetWishList(ownerId); Assert.AreEqual <int>(numberOfWishes + 1, list.Wishes.Count, "Number of wishes did not increase by one"); Wish loadedWish = (from w in list.Wishes where w.Name == newWish.Name select w).SingleOrDefault <Wish>(); Assert.IsNotNull(loadedWish, "Wish was null"); Assert.AreEqual <string>(newWish.Description, loadedWish.Description, "Description did not match"); }
public async Task ProviderOrchestrationAsync_Returns_Wish_Results() { var wishA = new Wish { Name = "wish", Query = "query" }; var wishB = new Wish { Name = "wish two", Query = "w.2" }; var providerCtx = new SearchProviderContext { Provider = new Provider(), Wishes = new[] { wishA, wishB } }; var context = new Mock <DurableOrchestrationContextBase>(MockBehavior.Strict); context.Setup(c => c.GetInput <SearchProviderContext>()).Returns(providerCtx); context.SetupSequence(c => c.CallActivityAsync <IEnumerable <WishResult> >("WishSearch", It.IsAny <object>())) .ReturnsAsync(new[] { new WishResult(), new WishResult() }). ReturnsAsync(new[] { new WishResult() }); var result = await _function.ProviderOrchestrationAsync(context.Object); context.Verify(c => c.GetInput <SearchProviderContext>(), Times.Once()); context.Verify(c => c.CallActivityAsync <IEnumerable <WishResult> >("WishSearch", It.IsAny <object>()), Times.Exactly(2)); Assert.Equal(3, result.Count()); }
public async Task SearchOrchestrationAsync_Persists_WishResults_And_Sends_A_Notification() { var wish = new Wish { Name = "wish", Query = "query", LastSearchDate = DateTime.UtcNow.AddDays(-2) }; var wishResult = new WishResult(); wishResult.BelongsTo(wish); var searchContext = new SearchContext { Providers = new[] { new Provider { ApiKey = "key", ApiUrl = "https://no.where" } }, Wishes = new[] { wish } }; var context = new Mock <DurableOrchestrationContextBase>(MockBehavior.Strict); var notifications = new Mock <IAsyncCollector <PushoverNotification> >(MockBehavior.Strict); context.Setup(c => c.GetInput <SearchContext>()).Returns(searchContext); context.Setup(c => c.CallSubOrchestratorAsync <IEnumerable <WishResult> >("ProviderOrchestration", It.IsAny <object>())) .ReturnsAsync(new[] { wishResult }); notifications.Setup(n => n.AddAsync(It.IsAny <PushoverNotification>(), CancellationToken.None)) .Returns(Task.CompletedTask); _wishTable.SetupBatch(); await _function.SearchOrchestrationAsync(context.Object, _wishTable.Object, notifications.Object); context.Verify(c => c.GetInput <SearchContext>(), Times.Once()); context.Verify(c => c.CallSubOrchestratorAsync <IEnumerable <WishResult> >("ProviderOrchestration", It.IsAny <object>()), Times.Once()); notifications.Verify(n => n.AddAsync(It.IsAny <PushoverNotification>(), CancellationToken.None), Times.Once()); _wishTable.VerifyBatch(); }
public IActionResult Update(long id, [FromBody] Wish item) { if (item == null || item.WishID != id) { return(BadRequest()); } var wish = _context.Wishes.FirstOrDefault(t => t.WishID == id); if (wish == null) { return(NotFound()); } wish.BuyerID = item.BuyerID; wish.Categorie = item.Categorie; wish.Description = item.Description; wish.ImageURL = item.ImageURL; wish.IsChecked = item.IsChecked; wish.Title = item.Title; wish.WishListID = item.WishListID; _context.Wishes.Update(wish); _context.SaveChanges(); return(new NoContentResult()); }
public BaseObject UpdateWish(Wish wish) { var obj = new BaseObject(); try { if (db.Wishes.Any(m => m.Title.Equals(wish.Title) && m.ID != wish.ID)) { obj.Tag = -2; obj.Message = "标题已存在!"; return(obj); } var w = db.Wishes.FirstOrDefault(m => m.ID == wish.ID); w.DateStart = DateTime.Now; w.Description = wish.Description; w.Hope = wish.Hope; w.Name = wish.Name; w.Title = wish.Title; w.WishDescription = wish.WishDescription; w.PictureFile = wish.PictureFile; db.SaveChanges(); obj.Tag = 1; } catch (Exception e) { obj.Tag = -1; obj.Message = e.Message; } return(obj); }
public async Task <IActionResult> PutWish([FromRoute] int id, [FromBody] Wish wish) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != wish.Id) { return(BadRequest()); } _context.Entry(wish).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WishExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Can_Edit_Wish() { //Create a new wish to edit Wish wish = repository.SaveWish(new Wish { Name = "EditTestWish", Description = "Some description", Owner = repository.GetUsers().WithId(1), LinkUrl = "http://www.google.com" }); Wish wishToEdit = new Wish { Name = "Changed name", Description = "Changed description", LinkUrl = "http://www.microsoft.com" }; IPrincipal user = new GenericPrincipal(new GenericIdentity("User 1", "Forms"), null); var result = controller.Edit(wish.Id, wishToEdit, user) as RedirectToRouteResult; Assert.IsNotNull(result, "Result was null or not redirecttorouteresult"); Assert.AreEqual("Show", result.RouteValues["action"]); Assert.AreEqual("List", result.RouteValues["controller"]); Assert.AreEqual(wish.Owner.Name, result.RouteValues["id"]); Wish loadedWish = repository.GetWishes().WithId(wish.Id); Assert.AreEqual(wishToEdit.Name, loadedWish.Name); Assert.AreEqual(wishToEdit.Description, loadedWish.Description); Assert.AreEqual(wishToEdit.LinkUrl, loadedWish.LinkUrl); }
public WishDTO GetWish(int id) { Wish wish = Dbase.Wishes.Get(id); Mapper.Initialize(cfg => cfg.CreateMap <Wish, WishDTO>()); return(Mapper.Map <Wish, WishDTO>(wish)); }
public ActionResult AddItem(long id) { var product = new ProductDao().GetDetail(id); var wishresult = new WishDao().FindByUserIdAndProductID(((User)Session[Constants.USER_INFO]).ID, id); if (wishresult == false) { Wish wish = new Wish(); wish.ProductID = id; wish.UserID = ((User)Session[Constants.USER_INFO]).ID; wish.CreateDate = DateTime.Now; wish.Status = 1; product.WishCount = product.WishCount + 1; var productDao = new ProductDao().Update(product); var result = new WishDao().Insert(wish); if (result) { new LogDao().SetLog("Add Item Wish", "Thành công", ((User)Session[Constants.USER_INFO]).ID); return(Redirect((string)Session[Constants.CURRENT_URL])); } else { new LogDao().SetLog("Add Item Wish", "Thất bại", ((User)Session[Constants.USER_INFO]).ID); return(Redirect((string)Session[Constants.CURRENT_URL])); } } new LogDao().SetLog("Add Item Wish", "Đã thêm" + product.Name.ToString(), ((User)Session[Constants.USER_INFO]).ID); return(Redirect((string)Session[Constants.CURRENT_URL])); }
private async Task <Result <WishModel> > Insert(int userId, IEnumerable <WishCreationModel> wishCreationModel) { foreach (var wishItem in wishCreationModel) { this.wishRepository.Add(Wish.Create(userId, wishItem.IdProduct).Value); } unitOfWork.Save(); var products = new List <ProductModel>(); foreach (var i in wishCreationModel) { products.Add(await this.productQueryRepository.GetById(i.IdProduct)); } var model = new WishModel { Id = userId, Products = products, }; var indexResult = await this.indexService.IndexDocumentAsync(model); if (indexResult.Failure) { await RollbackInsert(userId, wishCreationModel); return(OperationResult.InternalServerError <WishModel>(indexResult)); } return(OperationResult.Created(model)); }
public void AddCityToWish(CityDTO cityDTO, string currentUser) { //чи вже є в базі місто з таким id? City city = Dbase.Cities.Get(cityDTO.Id); if (city == null) { //чи вже є в базі місто з цими координатами? city = Dbase.Cities.Find(c => Math.Abs(c.GeoLat - cityDTO.GeoLat) > 1 && Math.Abs(c.GeoLong - cityDTO.GeoLong) > 1).FirstOrDefault(); if (city == null) { //add city to DB Mapper.Initialize(cfg => cfg.CreateMap <CityDTO, City>()); City newCity = Mapper.Map <CityDTO, City>(cityDTO); Dbase.Cities.Create(newCity); city = Dbase.Cities.Find(c => c.GeoLat == newCity.GeoLat && c.GeoLong == newCity.GeoLong).First(); } } //add wish to DB Wish wish = new Wish { CityId = city.Id, UserName = currentUser }; Dbase.Wishes.Create(wish); Dbase.Save(); }
public BaseObject UpdateWish(Wish wish) { using (WishLogic logic = new WishLogic(db)) { return(logic.UpdateWish(wish)); } }
public static WishViewModel ToViewModel(this Wish wish) => new WishViewModel { Id = wish.RowKey, Active = wish.Active, Name = wish.Name, Query = wish.Query, };
public async Task ExecuteAsync_Updates_The_Active_Property() { var wish = new Wish { RowKey = "123", Active = false }; _table.SetupSequence(t => t.ExecuteAsync(It.IsAny <TableOperation>())) .ReturnsAsync(new TableResult { Etag = "new", HttpStatusCode = 200, Result = new DynamicTableEntity(wish.PartitionKey, wish.RowKey, "new", new Dictionary <string, EntityProperty> { { "Active", new EntityProperty(false) } }) }) .ReturnsAsync(new TableResult { Etag = "new", HttpStatusCode = 200, Result = new DynamicTableEntity(wish.PartitionKey, wish.RowKey, "new", new Dictionary <string, EntityProperty> { { "Active", new EntityProperty(true) } }) }); var cmd = new ToggleWishCommand(wish.RowKey, true); await cmd.ExecuteAsync(_table.Object); _table.Verify(t => t.ExecuteAsync(It.Is <TableOperation>(op => op.OperationType == TableOperationType.Retrieve)), Times.Once()); _table.Verify(t => t.ExecuteAsync(It.Is <TableOperation>(op => op.OperationType == TableOperationType.Merge)), Times.Once()); }
public BaseObject AddWish(Wish wish) { using (WishLogic logic = new WishLogic(db)) { return(logic.AddWish(wish)); } }
public void SetWish(Wish w) { // Debug.Log($"Setting wish {w.type} {w.strength}\n"); interactable = true; if (w == null) { setCount(0, true); my_wish = w; Zoo.Instance.returnObject(info_box, true); Debug.Log("Setting null sprite?\n"); return; } else { my_wish = w; SetSprite("GUI/Inventory/" + w.type.ToString() + "_button_image"); info_box = Zoo.Instance.getObject("GUI/tiny_info/" + w.type.ToString() + "_tiny_info", false); info_box.transform.SetParent(transform); info_box.transform.localScale = Vector3.one; info_box.transform.localRotation = Quaternion.identity; info_box.transform.GetComponent <RectTransform>().anchoredPosition = Vector3.zero; updateInfoBoxLabel(); } }
public static void NullWish(this IGuardClause guardClause, int wishId, Wish wish) { if (wish == null) { throw new WishNotFoundException(wishId); } }
public Pikachu() { name = "Pikachu"; level = 100; nationalIdentifier = 25; defaultStats = new Dictionary <PokemonStat, int>(); defaultStats[PokemonStat.HP] = 211; defaultStats[PokemonStat.HP_MAX] = 211; defaultStats[PokemonStat.ATTACK] = 146; defaultStats[PokemonStat.DEFENSE] = 116; defaultStats[PokemonStat.SP_ATTACK] = 136; defaultStats[PokemonStat.SP_DEFENSE] = 136; defaultStats[PokemonStat.SPEED] = 216; attackActions = new AttackAction[4]; attackActions[0] = new Thunderbolt(); attackActions[1] = new QuickAttack(); attackActions[2] = new IronTail(); attackActions[3] = new Wish(); type = PokemonType.ELECTRIC; Init(); }
//GET /api/wishes public IHttpActionResult GetWishes() { IList <Wish> wishes = new List <Wish>(); foreach (var item in service.GetMany()) { Wish wish = new Wish() { WishID = item.WishID, //Kid = item.Kid, KidID = item.KidID, Desc = item.Desc, ExpirationDate = item.ExpirationDate, FundRaised = item.FundRaised, FundToRaise = item.FundToRaise }; wishes.Add(wish); } if (wishes.Count == 0) { return(NotFound()); } return(Ok(wishes)); }
public void GetBusinessesTest() { Wish wish = GetSimpleWish(); wish.WishBusinesses = new List <WishBusinesses>() { new WishBusinesses(new Business("a") { Id = 0 }, wish), new WishBusinesses(new Business("a") { Id = 1 }, wish), new WishBusinesses(new Business("a") { Id = 2 }, wish), new WishBusinesses(new Business("a") { Id = 3 }, wish) }; List <Business> businessList = wish.GetBusinesses().ToList(); Assert.AreEqual(4, businessList.Count, "GetBusinesses returned wrong amount of businesses"); Assert.AreEqual(2, businessList[2].Id, "GetBusinesses returned wrong businesses"); }
public void GetInterestsTest() { Wish wish = GetSimpleWish(); wish.WishInterests = new List <WishInterests>() { new WishInterests(new Interest("a") { Id = 0 }, wish), new WishInterests(new Interest("a") { Id = 1 }, wish), new WishInterests(new Interest("a") { Id = 2 }, wish), new WishInterests(new Interest("a") { Id = 3 }, wish) }; List <Interest> interestList = wish.GetInterests().ToList(); Assert.AreEqual(4, interestList.Count, "GetInterest returned wrong amount of interests"); Assert.AreEqual(2, interestList[2].Id, "GetInterest returned wrong interests"); }
public void hitWish(Wish newWish) { if (heldWish != null) { if (heldWish == newWish) return; heldWish.enabled = true; } heldWish = newWish; wishGrabSound.Play(); secretsTextUI.text = newWish.secretText; newWish.enabled = false; }
public void enteredRealm(Universe u) { realmTextUI.text = "You have entered the " + u.type + " well."; missedPortalAudioBlockTimeStart = Time.realtimeSinceStartup; missedPortalAudioBlock = true; if( heldWish != null && u.type == heldWish.type ) { secretsTextUI.text = "You have granted the wish by bringing it to the correct well!"; successfulWishDropSound.Play(); if (wishesGranted < 2) { wishesGranted++; if (wishesGranted == 2) { preventFinalWish = false; } } else { if( heldWish.secretText == Wish.winWish && !gameEnded ) { secretsTextUI.text = "You have granted your lover's wish. You win!"; this.enabled = false; gameEnded = true; currentWellMusic.Stop(); gameEndMusic.Play(); // show the end movie quad endMovieQuad.gameObject.SetActive(true); // REALLY show it - workaround for portal teleport bug endMovieQuad.transform.localPosition = new Vector3(0f, -8.19f, 8.9f); StartCoroutine(waitLoadEndMovie()); } } heldWish.enabled = true; heldWish = null; } else if( heldWish != null ) { wrongWishDropSound.Play(); } if(!gameEnded) { StartCoroutine("ChangeMusic", u.wellMusic); } }