Beispiel #1
0
        public object GenerateDiet(int userid, UserInformation userdata)
        {
            DateTime lastupdate = GetLastUpdate(userid);

            if (DateTime.Now.Month > lastupdate.Month)
            {
                var      user           = MyGymContext.DB.Usuario.Find(userid);
                DateTime olddateofbirth = user.FechaNacimiento;
                double   oldweigth      = user.Peso;
                double   oldheight      = user.Estatura;
                if (userdata.DateOfBirth != null)
                {
                    user.FechaNacimiento = userdata.DateOfBirth;
                }
                if (userdata.Weight != default(double))
                {
                    user.Peso = userdata.Weight;
                }
                if (userdata.Height != default(double))
                {
                    user.Estatura = userdata.Height;
                }
                MyGymContext.DB.SaveChanges();
                if (user.FechaNacimiento != olddateofbirth | user.Peso != oldweigth | user.Estatura != oldheight)
                {
                    new DietRepository().CreateDiet(user.UsuarioID);
                }
                return(APIFunctions.SuccessResult(new object(), JsonMessage.Success));
            }
            return(APIFunctions.ErrorResult(JsonMessage.CannotChangeProperty));
        }
Beispiel #2
0
        public object GetUserDiet(int userid, string day)
        {
            Dia dia  = (Dia)Enum.Parse(typeof(Dia), day);
            var diet = MyGymContext.DB.Dieta.FirstOrDefault(item => item.UsuarioID == userid & item.Dia == dia);

            if (diet == null)
            {
                return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "Dieta")));
            }
            var recomendations = MyGymContext.DB.Tiene.Where(item => item.DietaID == diet.DietaID);

            if (recomendations.Count() > 0)
            {
                return(APIFunctions.SuccessResult(
                           recomendations.Select(item => new UserDiet()
                {
                    DietID = diet.DietaID,
                    ImageURL = string.Format("http://localhost:8000/images/{0}.jpg", item.RecomendacionID),
                    MealTime = new List <TiempoComida>(item.Recomendacion.SeRecomiendaEn.Select(tc => tc.TiempoDeComida.Nombre)),
                    Name = item.Recomendacion.Nombre,
                    RecomendationID = item.RecomendacionID
                }), JsonMessage.Success));
            }
            return(APIFunctions.ErrorResult(JsonMessage.Error));
        }
Beispiel #3
0
        public object LogIn(string user, string password)
        {
            var result = MyGymContext.DB.Usuario.FirstOrDefault(item => (item.Email == user | item.Nick == user) & item.Password == password);

            if (result == null)
            {
                return(APIFunctions.ErrorResult(JsonMessage.ErrorLogin));
            }
            return(APIFunctions.SuccessResult(APIFunctions.UsuarioToUser(result), JsonMessage.Success));
        }
Beispiel #4
0
        public object Get(int userid)
        {
            Usuario user = MyGymContext.DB.Usuario.Find(userid);

            if (user == null)
            {
                return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "Usuario")));
            }
            return(APIFunctions.SuccessResult(APIFunctions.UsuarioToUser(user), JsonMessage.Success));
        }
 public object GetByCategoryID(int categoryID)
 {
     try
     {
         return(APIFunctions.SuccessResult(CuerosContext.DB.Categories.Find(categoryID), JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #6
0
 public object Get()
 {
     try
     {
         return(APIFunctions.SuccessResult(CuerosContext.DB.Products.ToList(), "JDKLASJDKLJDKLSKLS!"));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #7
0
 public object Get()
 {
     try
     {
         return(APIFunctions.SuccessResult(CuerosContext.DB.Materials.ToList(), JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #8
0
 public object GetByProductID(int productID)
 {
     try
     {
         var result = from x in CuerosContext.DB.Orders.ToList() where x.ProductID == productID select x;
         return(APIFunctions.SuccessResult(result.ToList(), JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #9
0
 public object Get()
 {
     try
     {
         var result = CuerosContext.DB.Orders.ToList();
         return(APIFunctions.SuccessResult(result, JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #10
0
 public object GetByProductID(int productID)
 {
     try
     {
         return(APIFunctions.SuccessResult(
                    from x in CuerosContext.DB.Compose.ToList()
                    where x.ProductID == productID
                    select x.Material, JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #11
0
        public object GetUserRecord(int userid, string filter, int weekscount)
        {
            IEnumerable <UserRecord> datas = default(IEnumerable <UserRecord>);

            if (filter.Equals("month"))
            {
                datas = MyGymContext.DB.Historial.Where(
                    item => item.UsuarioID == userid).Select(e =>
                                                             new UserRecord()
                {
                    Weight            = e.Peso,
                    Heigth            = e.Estatura,
                    Date              = e.Fecha,
                    NutritionalStatus = e.EstadoNutricional
                });
            }
            else if (filter.Equals("week"))
            {
                var query = MyGymContext.DB.Historial.Where(
                    item => item.UsuarioID == userid).
                            OrderBy(item => item.Fecha);
                if (query.Count() > weekscount)
                {
                    datas = query.Take(weekscount).
                            Select(e => new UserRecord()
                    {
                        Weight            = e.Peso,
                        Heigth            = e.Estatura,
                        Date              = e.Fecha,
                        NutritionalStatus = e.EstadoNutricional
                    });
                }
                else
                {
                    datas = query.Select(e => new UserRecord()
                    {
                        Weight            = e.Peso,
                        Heigth            = e.Estatura,
                        Date              = e.Fecha,
                        NutritionalStatus = e.EstadoNutricional
                    });
                }
            }
            if (datas.Count() > 0)
            {
                return(APIFunctions.SuccessResult(datas, JsonMessage.Success));
            }
            return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "Reportes")));
        }
Beispiel #12
0
 public object Get(int supplierID)
 {
     try
     {
         var supplier = CuerosContext.DB.Suppliers.Find(supplierID);
         if (supplier == null)
         {
             return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "proveedor")));
         }
         return(APIFunctions.SuccessResult(supplier, JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #13
0
 public object Get(int productID)
 {
     try
     {
         var product = CuerosContext.DB.Products.Find(productID);
         if (product == null)
         {
             return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "producto")));
         }
         return(APIFunctions.SuccessResult(product, JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #14
0
 public object Add(Order order)
 {
     try
     {
         if (!ValidateOrder(order))
         {
             //error x el numero de prendas
             return(APIFunctions.ErrorResult("Cantidad disponible excedida o error en datos de envio"));
         }
         var newOrder = CuerosContext.DB.Orders.Add(order);
         return(APIFunctions.SuccessResult(newOrder.OrderID, JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #15
0
 public object Add(Supplier supplier)
 {
     try
     {
         if (!ValidateSupplier(supplier))
         {
             return(APIFunctions.ErrorResult("Error en los datos"));
         }
         var newSupplier = CuerosContext.DB.Suppliers.Add(supplier);
         CuerosContext.DB.SaveChanges();
         return(APIFunctions.SuccessResult(newSupplier.SupplierID, JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #16
0
 public object Add(Product product)
 {
     try
     {
         if (!ValidateProduct(product))
         {
             return(APIFunctions.ErrorResult("Error en los datos"));
         }
         var newProduct = CuerosContext.DB.Products.Add(product);
         CuerosContext.DB.SaveChanges();
         return(APIFunctions.SuccessResult(newProduct.ProductID, JsonMessage.Success));
     }
     catch (Exception e)
     {
         return(APIFunctions.ErrorResult(e.Message));
     }
 }
Beispiel #17
0
 public object Delete(int userid)
 {
     try
     {
         Usuario user = MyGymContext.DB.Usuario.Find(userid);
         if (user == null)
         {
             return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "Usuario")));
         }
         MyGymContext.DB.Usuario.Remove(user);
         MyGymContext.DB.SaveChanges();
         return(APIFunctions.SuccessResult(new object(), JsonMessage.Success));
     }
     catch (Exception ex)
     {
         return(APIFunctions.ErrorResult(ex.Message));
     }
 }
Beispiel #18
0
 public object Add(UserInformation user)
 {
     try
     {
         if (!ValidateUser(user.Email, user.Nick))
         {
             return(APIFunctions.ErrorResult(JsonMessage.NotFound));
         }
         Usuario newuser = MyGymContext.DB.Usuario.Add(APIFunctions.UserToUsuario(user));
         MyGymContext.DB.SaveChanges();
         // Generamos la dieta
         //new DietRepository().CreateDiet(newuser.UsuarioID);
         return(APIFunctions.SuccessResult(newuser.UsuarioID, JsonMessage.Success));
     }
     catch (Exception ex)
     {
         return(APIFunctions.ErrorResult(ex.Message));
     }
 }
Beispiel #19
0
        private object toSerializable(Ejercicio ejercicio)
        {
            UserExercise exercise = new UserExercise()
            {
                ExerciseID   = ejercicio.EjercicioID,
                Name         = ejercicio.Nombre,
                Distance     = ejercicio.Distancia,
                Duration     = ejercicio.Duracion,
                Repetitons   = ejercicio.Repeticiones,
                Sets         = ejercicio.Sets,
                Type         = ejercicio.Tipo.ToString(),
                Weight       = ejercicio.Peso,
                Instructions = (from x in ejercicio.Instruccion select new Instruction()
                {
                    Content = x.Content, Number = x.Step
                }).ToList()
            };

            return(APIFunctions.SuccessResult(exercise, JsonMessage.Success));
        }
Beispiel #20
0
        public object Update(UserInformation user)
        {
            try
            {
                Usuario olduser = MyGymContext.DB.Usuario.Find(user.UserID);
                if (olduser == null)
                {
                    return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "Usuario")));
                }
                if (user.PhysicalComplexion != olduser.ComplexionFisica)
                {
                    olduser.ComplexionFisica = user.PhysicalComplexion;
                }
                if (user.LastName != null & user.LastName != string.Empty)
                {
                    olduser.Materno = user.LastName;
                }
                if (user.Names != null & user.Names != string.Empty)
                {
                    olduser.Nombre = user.Names;
                }
                if (user.Password != null & user.Password != string.Empty)
                {
                    olduser.Password = user.Password;
                }
                if (user.FirstName != null & user.FirstName != string.Empty)
                {
                    olduser.Paterno = user.FirstName;
                }
                if (user.Sex != olduser.Sexo)
                {
                    olduser.Sexo = user.Sex;
                }

                if (user.Nick != null & user.Nick != string.Empty)
                {
                    Usuario finduser = MyGymContext.DB.Usuario.FirstOrDefault(item => item.Nick == user.Nick & item.UsuarioID != olduser.UsuarioID);
                    if (finduser != null)
                    {
                        return(APIFunctions.ErrorResult(string.Format(JsonMessage.Error, "Nick")));
                    }
                    olduser.Nick = user.Nick;
                }
                if (user.Email != null & user.Email != string.Empty)
                {
                    Usuario finduser = MyGymContext.DB.Usuario.FirstOrDefault(item => item.Email == user.Email & item.UsuarioID != olduser.UsuarioID);
                    if (finduser != null)
                    {
                        return(APIFunctions.ErrorResult(string.Format(JsonMessage.Error, "Email")));
                    }
                    olduser.Email = user.Email;
                }

                //DateTime olddateofbirth = olduser.FechaNacimiento;
                //double oldweigth = olduser.Peso;
                //double oldheight = olduser.Estatura;

                //if (user.DateOfBirth != null | user.Weight != default(double) | user.Height != default(double))
                //{
                //    if (user.DateOfBirth != null) olduser.FechaNacimiento = user.DateOfBirth;
                //    if (user.Weight != default(double)) olduser.Peso = user.Weight;
                //    if (user.Height != default(double)) olduser.Estatura = user.Height;
                //}
                MyGymContext.DB.SaveChanges();
                //if (olduser.FechaNacimiento != olddateofbirth | olduser.Peso != oldweigth | olduser.Estatura != oldheight)
                //{
                //    new DietRepository().CreateDiet(olduser.UsuarioID);
                //}
                return(APIFunctions.SuccessResult(new { userid = olduser.UsuarioID }, JsonMessage.Success));
            }
            catch (Exception ex)
            {
                return(APIFunctions.ErrorResult(ex.Message));
            }
        }
Beispiel #21
0
        public object GenerateRoutine(int UsuarioId, bool mode)
        {
            var user = MyGymContext.DB.Usuario.Find(UsuarioId);

            if (user == null)
            {
                return(APIFunctions.ErrorResult(string.Format(JsonMessage.NotFound, "Usuario")));
            }
            Rutina rutina = new Rutina();

            rutina.UsuarioID = user.UsuarioID;
            MyGymContext.DB.Rutina.Add(rutina);
            MyGymContext.DB.SaveChanges();
            DateTime date = new DateTime();

            date = System.DateTime.Now;
            List <Actividad> activities = GetSorted(mode).ToList();

            if (mode)
            {
                for (int i = 0; i < 12; i++)
                {
                    if (i % 4 == 3)
                    {
                        activities.Insert(i, new Actividad()
                        {
                            EjercicioID = 1, Fecha = DateTime.Now.AddDays(i), RutinaID = rutina.RutinaID
                        });
                    }
                    else
                    {
                        activities[i].Fecha    = DateTime.Now.AddDays(i);
                        activities[i].RutinaID = rutina.RutinaID;
                    }
                    MyGymContext.DB.Actividad.Add(activities[i]);
                    MyGymContext.DB.SaveChanges();
                }
                return(APIFunctions.SuccessResult(toSerializable(activities), JsonMessage.Success));
            }
            else
            {
                for (int i = 0; i < 21; i++)
                {
                    if (i % 7 == 5 || i % 7 == 6)
                    {
                        activities.Insert(i, new Actividad()
                        {
                            EjercicioID = 1, Fecha = DateTime.Now.AddDays(i), RutinaID = rutina.RutinaID
                        });
                    }
                    else
                    {
                        activities[i].Fecha    = DateTime.Now.AddDays(i);
                        activities[i].RutinaID = rutina.RutinaID;
                    }
                    MyGymContext.DB.Actividad.Add(activities[i]);
                    MyGymContext.DB.SaveChanges();
                }
                return(APIFunctions.SuccessResult(toSerializable(activities), JsonMessage.Success));
            }
        }