public ActionResult Sign(Campaign campaign, int?id) { campaign = db.Campaigns.Find(id); //Campaign campaign = db.Campaigns.Where() CampaignSignViewModel viewModel = new CampaignSignViewModel(); var user = User.Identity.Name; UserProfileInfo profile = db.UserProfileInfo.Where(x => x.Username == user).FirstOrDefault(); ProfileViewModel model = new ProfileViewModel { Address = profile.Address, ZipCode = profile.ZipCode, FirstName = profile.FirstName, LastName = profile.LastName, CellPhone = profile.CellPhone, BirthDate = profile.BirthDate, //Activity = profile.Activity }; SignUpList list = new SignUpList(); list.FirstName = profile.FirstName; list.LastName = profile.LastName; list.UserID = profile.UserID; list.CampaignID = campaign.CampaignID; list.CampaignName = campaign.CampaignName; //list.DateSigned = System.DateTime.Now; foreach (var item in db.SignnUpList) { if (list.UserID == item.UserID && list.CampaignID == item.CampaignID) { return(RedirectToAction("AlreadySigned", "SignUpList")); } } //if (db.SignnUpList.Any((o => o.UserID == list.UserID))) //{ // if (db.SignnUpList(o => o.CampaignID == list.CampaignID)) // { // return RedirectToAction("AlreadySigned", "SignUpList"); // } //} campaign.UsersSignedUp = campaign.UsersSignedUp + 1; //campaign.UsersSignedUp++; //var item = from n in db.Campaigns // where n.CampaignID == Int32.Parse(Request.QueryString["CampaignID"]) // select n; //item.UsersSignedUp += //db.Entry(campaign).State = EntityState.Modified; //db.SaveChanges(); db.SignnUpList.Add(list); db.SaveChanges(); return(RedirectToAction("Index", "Campaign")); }
/// <param name='brand'> /// Required. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> public async Task <HttpOperationResponse <SignUpList> > GetAllSignUpsWithOperationResponseAsync(string brand, CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { // Validate if (brand == null) { throw new ArgumentNullException("brand"); } // Tracing bool shouldTrace = ServiceClientTracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("brand", brand); ServiceClientTracing.Enter(invocationId, this, "GetAllSignUpsAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/brands/"; url = url + Uri.EscapeDataString(brand); url = url + "/signups"; string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Credentials if (this.Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (shouldTrace) { ServiceClientTracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); HttpResponseMessage httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { ServiceClientTracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); if (statusCode != HttpStatusCode.OK) { HttpOperationException <object> ex = new HttpOperationException <object>(); ex.Request = httpRequest; ex.Response = httpResponse; ex.Body = null; if (shouldTrace) { ServiceClientTracing.Error(invocationId, ex); } throw ex; } // Create Result HttpOperationResponse <SignUpList> result = new HttpOperationResponse <SignUpList>(); result.Request = httpRequest; result.Response = httpResponse; // Deserialize Response if (statusCode == HttpStatusCode.OK) { SignUpList resultModel = new SignUpList(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null) { resultModel.DeserializeJson(responseDoc); } result.Body = resultModel; } if (shouldTrace) { ServiceClientTracing.Exit(invocationId, result); } return(result); }