Example #1
0
        public async Task <Punkty4> PostPoints32(Punkty3 punkty3)
        {
            if (punkty3 == null)
            {
                return(null);
            }
            if (punkty3.PointList == null)
            {
                //return BadRequest(ModelState);
                return(null);
            }
            Route route = new Route
            {
                Name        = punkty3.Name,
                Description = punkty3.Description,
                UserId      = RequestContext.Principal.Identity.GetUserId(),
                UserName    = RequestContext.Principal.Identity.GetUserName(),
                ImageUrl    = punkty3.ImageUrl,
            };

            db.Routes.Add(route);
            await db.SaveChangesAsync();

            Punkty4 output = new Punkty4();

            output.route    = route;
            output.Points3s = new List <Points3>();

            foreach (Points3 points3 in punkty3.PointList)
            {
                points3.RouteId  = route.Id;
                points3.UserId   = RequestContext.Principal.Identity.GetUserId();
                points3.UserName = RequestContext.Principal.Identity.GetUserName();
                db.Points3.Add(points3);
                await db.SaveChangesAsync();

                output.Points3s.Add(points3);
            }


            // return CreatedAtRoute("DefaultApi", new { id = route.Id }, punkty3);
            //   return CreatedAtRoute()
            return(output);
        }
Example #2
0
        public async Task <Punkty4> PostPoints32(Punkty5 punkty5)
        {
            if (punkty5 == null)
            {
                return(null);
            }
            if (punkty5.PointList == null)
            {
                //return BadRequest(ModelState);
                return(null);
            }
            Route route = await db.Routes.FindAsync(punkty5.id);

            if (route == null)
            {
                return(null);
            }
            Punkty4 output = new Punkty4();

            output.route = route;

            output.Points3s = new List <Points3>();

            foreach (Points3 points3 in punkty5.PointList)
            {
                points3.RouteId  = route.Id;
                points3.UserId   = RequestContext.Principal.Identity.GetUserId();
                points3.UserName = RequestContext.Principal.Identity.GetUserName();
                db.Points3.Add(points3);
                await db.SaveChangesAsync();

                output.Points3s.Add(points3);
            }


            // return CreatedAtRoute("DefaultApi", new { id = route.Id }, punkty3);
            //   return CreatedAtRoute()
            return(output);
        }
Example #3
0
        // [FromBody]
        public async Task <Punkty4> PostPoints32(Punkty2 punkty2)
        {
            if (punkty2 == null)
            {
                return(null);
            }
            if (punkty2.UpdateList == null)
            {
                return(null);
            }
            Route route = new Route
            {
                Name        = punkty2.Name,
                Description = punkty2.Description,
                UserId      = RequestContext.Principal.Identity.GetUserId(),
                UserName    = RequestContext.Principal.Identity.GetUserName(),
                ImageUrl    = punkty2.ImageUrl,
            };

            db.Routes.Add(route);
            await db.SaveChangesAsync();

            Punkty4 output = new Punkty4();

            output.route    = route;
            output.Points3s = new List <Points3>();
            // List<int> lista = list2.To
            foreach (int n in punkty2.UpdateList)

            {
                int id = n;


                Points3 points3 = await db.Points3.FindAsync(id);

                if (points3 == null)
                {
                }
                else
                {
                    points3.RouteId         = route.Id;
                    db.Entry(points3).State = EntityState.Modified;
                    points3.UserId          = RequestContext.Principal.Identity.GetUserId();
                    points3.UserName        = RequestContext.Principal.Identity.GetUserName();

                    output.Points3s.Add(points3);
                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!Points3Exists(id))
                        {
                            //  return NotFound();
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
            return(output);



            //if (id != points3.Id)
            //{
            //    return BadRequest();
            //}


            //  return StatusCode(HttpStatusCode.NoContent);
        }