コード例 #1
0
        public async Task <IActionResult> PutWidgets(int id, Widgets widgets)
        {
            if (id != widgets.Id)
            {
                return(BadRequest());
            }

            _context.Entry(widgets).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WidgetsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PatchWidgets(int account_id, string uuid, [FromBody] JsonPatchDocument <Widgets> widgets)
        {
            if (widgets.Operations.Count != 0)
            {
                var widget = await _context.Widgets.Where(w => w.AccountId == account_id && String.Equals(w.UUID, uuid)).FirstOrDefaultAsync();

                if (widget != null)
                {
                    //var elementsWithPathPurpose = widgets.Operations.Where(o => o.path.Equals("Purpose")).FirstOrDefault();

                    //if (elementsWithPathPurpose != null)
                    //{
                    //    var _purpose = await _context.Purposes.Where(p => string.Equals(elementsWithPathPurpose.value.ToString(), p.Purpose, StringComparison.OrdinalIgnoreCase)).FirstOrDefaultAsync();
                    //    if (_purpose != null && string.Equals(elementsWithPathPurpose.value.ToString(), _purpose.Purpose, StringComparison.OrdinalIgnoreCase)==false)
                    //    {
                    //        widgets.Replace(e=>e.PurposeId, _purpose.Id);
                    //    }
                    //}

                    widget.UpdatedTimeUTC = DateTime.UtcNow;

                    widgets.ApplyTo(widget, ModelState);


                    if (!ModelState.IsValid)
                    {
                        return(new BadRequestObjectResult(new { Success = false }));
                    }
                    _context.Entry(widget).State = EntityState.Modified;
                    try
                    {
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!WidgetsExists(account_id))
                        {
                            return(NotFound(new { Success = false, Message = "Widget with supplied " + account_id + " is not Existed" }));
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    return(NotFound(new { Success = false, Message = "Widget Not Found" }));
                }

                return(Ok(new { Success = true, widget = widget }));
            }
            else
            {
                return(Ok(new { Success = false, Message = "No Operations/Values Specified For Patching" }));
            }
        }
        public async Task <ActionResult <CustomerIpInformation> > InsertCustomerIpInformation(int widget_id, int customerId, CustomerIpInformation customerIpInformation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            string curURL = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";

            //    string ip = Response.HttpContext.Connection.RemoteIpAddress.ToString();
            // string externalIP;
            // externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
            //  externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
            //  .Matches(externalIP)[0].ToString();

            //  if (ip == "::1")
            //  {
            // ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString();
// ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString();
            //   }

            var widget = await _context.Widgets.FindAsync(widget_id);

            var customerIpInformations = new CustomerIpInformation();
            var conversationMessage    = new ConversationMessages();

            if (widget != null)
            {
                customerIpInformations.HttpURL        = customerIpInformation.HttpURL;
                customerIpInformations.ClientIp       = customerIpInformation.ClientIp; // externalIP;
                customerIpInformations.CustomerId     = customerId;
                customerIpInformations.CreatedTimeUTC = DateTime.UtcNow;
                customerIpInformations.HttpReferrer   = customerIpInformation.HttpURL;



                _context.CustomerIpInformation.Add(customerIpInformations);
                await _context.SaveChangesAsync();

                return(Ok(customerIpInformations));
            }
            else
            {
                return(BadRequest("No such widget"));
            }
        }