public async Task <ActionResult> Create([Bind(Include = "Id,BusinessDomainId,CityId,MapJsonCoord,Description,Information,WorkTime,WorkTimeSaturday,WorkTimeSunday")] Address address) { if (ModelState.IsValid) { db.Addresses.Add(address); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.BusinessDomainId = new SelectList(db.BusinessDomains, "Id", "Name", address.BusinessDomainId); ViewBag.CityId = new SelectList(db.Cities, "Id", "NameMultiLangJson", address.CityId); return(View(address)); }
//[ResponseType(typeof(PromotionItem))] public async Task <IHttpActionResult> GetLike(long id) { try { PromotionItem item = _ctx.PromotionItems.Find(id); if (item == null) { throw new BusinessLogicException("не удается найти акцию"); } if (item.GetUserLike(UserId)?.Value == LikeType.Like) { return(Ok(new { item.LikeCount, item.DislikeCount })); } ; if (item.GetUserLike(UserId)?.Value == LikeType.Dislike) { Like like = item.GetUserLike(UserId); like.Value = LikeType.Like; item.DislikeCount = item.DislikeCount - 1; item.LikeCount = item.LikeCount + 1; } if (item.GetUserLike(UserId) == null) { _ctx.Likes.Add(new Like(UserId, item.Id, LikeType.Like)); item.LikeCount = item.LikeCount + 1; } /* * The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.Like_dbo.User_UserId". The conflict occurred in database "tukiflydatabase", table "dbo.User", column 'Id'. * The statement has been terminated. */ if (_ctx.ChangeTracker.HasChanges()) { await _ctx.SaveChangesAsync(); } return(Ok(new { item.LikeCount, item.DislikeCount }));; } catch (Exception ex) { Log.Error(ex.Message); throw; } }
public async Task <int> CompleteAsync() { return(await _context.SaveChangesAsync()); }