コード例 #1
0
        public async Task CreatePeladaAsync(Pelada p)
        {
            var    list = p.Teams.ToList()[0];
            string name = list.Name;

            context.Pelada.Add(p);
            await context.SaveChangesAsync();
        }
コード例 #2
0
 public Pelada Create(Pelada obj)
 {
     try
     {
         var newPelada = _unitOfWork.PeladaRepository.Create(obj);
         _unitOfWork.Save();
         return(newPelada);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #3
0
        public JsonResult Post([FromBody] Pelada obj)
        {
            try
            {
                var pelada = _peladaService.Create(obj);

                return(Json(pelada));
            }
            catch (Exception ex)
            {
                return(Json(ex));
            }
        }
コード例 #4
0
        public JsonResult Create([FromBody] Pelada obj)
        {
            try
            {
                var op        = new CreatePeladaOp(_unitOfWork);
                var newPelada = op.Execute(obj);

                var peladaViewModel = _mapper.Map <PeladaViewModel>(newPelada);

                return(Json(peladaViewModel));
            }
            catch (Exception ex)
            {
                return(FormatException(ex));
            }
        }
コード例 #5
0
        public async Task <ActionResult> Create(Pelada pelada)
        {
            try
            {
                await repository.CreatePeladaAsync(pelada);
            }
            catch (Exception e)
            {
                return(BadRequest(new
                {
                    error = string.Format("Parâmetros inválidos - Error {0}", e.Message)
                }));
            }

            return(RedirectToAction("Get", new { id = pelada.Id }));
        }
コード例 #6
0
        public async Task <bool> UpdatePeladaAsync(int id, Pelada p)
        {
            var pelada = await this.FindPeladaAsync(id);

            if (pelada != null)
            {
                pelada.Title       = p.Title;
                pelada.Description = p.Description;
                pelada.Place       = p.Place;
                await context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
コード例 #7
0
        public static void EnsureSeedData(this Context context)
        {
            if (context.AllMigrationsApplied())
            {
                if (!context.User.Any())
                {
                    var user1 = new User {
                        Email = "*****@*****.**", FirstName = "Andre", LastName = "Miranda", Password = Password.hash("andresiri", "*****@*****.**")
                    };
                    var user2 = new User {
                        Email = "*****@*****.**", FirstName = "Helio", LastName = "Feliciano", Password = Password.hash("andresiri", "*****@*****.**")
                    };

                    context.User.AddRange(user1, user2);

                    context.SaveChanges();
                }

                if (!context.Pelada.Any())
                {
                    var user1   = context.User.First(w => w.FirstName.Equals("Andre"));
                    var pelada1 = new Pelada {
                        Description = "Pelada Teste", CreatedByUserId = user1.Id
                    };

                    context.Pelada.AddRange(pelada1);

                    context.SaveChanges();
                }

                if (!context.Arena.Any())
                {
                    var arena1 = new Arena {
                        Description = "Arena Capim Macio"
                    };
                    var arena2 = new Arena {
                        Description = "Arena Nova Descoberta"
                    };

                    context.Arena.AddRange(arena1, arena2);

                    context.SaveChanges();
                }
            }
        }
コード例 #8
0
        public async Task <ActionResult> Update(int id, Pelada pelada)
        {
            try
            {
                if (await repository.UpdatePeladaAsync(id, pelada))
                {
                    return(Ok(new { message = "Pelada atualizada com sucesso !" }));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(new
                {
                    error = string.Format("Parâmetros inválidos - Error {0}", e.Message)
                }));
            }

            return(NotFound(new { message = "Pelada não encontrada !" }));
        }
コード例 #9
0
ファイル: DbInitializer.cs プロジェクト: andresiri/cdp-api
        public static List <Pelada> InsertPeladas(UnitOfWork unitOfWork, List <User> users)
        {
            var peladas = new Pelada[]
            {
                new Pelada {
                    Name = "Pelada grotesca", Day = WeekdayEnum.TUESDAY, CreatedByUserId = users[0].Id
                },
                new Pelada {
                    Name = "Pelada da Massa", Day = WeekdayEnum.MONDAY, CreatedByUserId = users[0].Id
                },
                new Pelada {
                    Name = "Pelada do floresta encantada", Day = WeekdayEnum.FRIDAY, CreatedByUserId = users[1].Id
                }
            };

            var newPeladas = new List <Pelada>();

            foreach (var pelada in peladas)
            {
                newPeladas.Add(unitOfWork.PeladaRepository.Create(pelada));
            }

            return(newPeladas);
        }