public Response <Category> Update(Category element)
 {
     try
     {
         Category updateCategory;
         using (TTDBEntities db = new TTDBEntities())
         {
             updateCategory = db.Categories.Find(element.IdCategory);
             if (element.CategoryName != null)
             {
                 updateCategory.CategoryName = element.CategoryName;
             }
             else if (element.Details != null)
             {
                 updateCategory.Details = element.Details;
             }
             db.Entry(updateCategory);
             db.SaveChanges();
         }
         return(new Response <Category>(null, updateCategory.IdCategory, true, null));
     }
     catch (Exception err)
     {
         return(new Response <Category>(err, null, false, null));
     }
 }
Exemple #2
0
        public JsonResult LoginWithFaceBook(string fbID) //, string fbEmail = "")
        {
            using (var db = new TTDBEntities())
            {
                /************************************************************************/
                /* find if login previously                                             */
                /************************************************************************/
                var result = from it in db.webpages_OAuthMembership
                             where it.Provider == @"facebook" && it.ProviderUserId == fbID
                             select it.UserId;

                if (result.Count() == 0)
                {
                    var ad = new webpages_OAuthMembership()
                    {
                        Provider       = @"facebook",
                        ProviderUserId = fbID
                    };

                    var au = new UserProfile()
                    {
                        UserName = fbID,
                        Email    = fbID
                    };

                    db.UserProfile.Add(au);
                    db.SaveChanges();

                    ad.UserId = ad.UserId;
                    db.webpages_OAuthMembership.Add(ad);
                    db.SaveChanges();

                    return(loginReturn(true, fbID));
                }
                else
                {
                    return(loginReturn(true, (from iter in db.UserProfile
                                              where iter.UserId == result.FirstOrDefault()
                                              select iter.UserName).FirstOrDefault()));
                }
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        public JsonResult CreatMemberShip(string name, string pwd)
        {
            try
            {
                using (var db = new TTDBEntities())
                {
                    if ((from it in db.UserProfile
                         where it.UserName == name
                         select it).Count() > 0)
                    {
                        return(loginReturn(false, ""));
                    }

                    var nUser = new UserProfile()
                    {
                        UserName = name, Email = pwd
                    };
                    db.UserProfile.Add(nUser);
                    db.SaveChanges();
                    var nMem = new webpages_Membership()
                    {
                        Password = pwd, PasswordSalt = "", PasswordFailuresSinceLastSuccess = 0
                    };
                    nMem.UserId = nUser.UserId;
                    db.webpages_Membership.Add(nMem);
                    db.SaveChanges();

                    return(loginReturn(true, name));
                }
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex);
                return(loginReturn(false, ""));
            }
        }
 public Response <Category> Post(Category element)
 {
     try
     {
         using (TTDBEntities db = new TTDBEntities())
         {
             db.Categories.Add(element);
             db.SaveChanges();
         }
         return(new Response <Category>(null, element.IdCategory, true, null));
     }
     catch (Exception err)
     {
         return(new Response <Category>(err, null, false, null));
     }
 }
Exemple #5
0
 public Response <Artist> Post(Artist element)
 {
     try
     {
         using (TTDBEntities db = new TTDBEntities())
         {
             db.Artists.Add(element);
             db.SaveChanges();
         }
         return(new Response <Artist>(null, element.IdArtist, true, null));
     }
     catch (Exception err)
     {
         return(new Response <Artist>(err, null, false, null));
     }
 }
 public Response <Category> Delete(int idElement1, int idElement2 = 0)
 {
     try
     {
         Category delCategory;
         using (TTDBEntities db = new TTDBEntities())
         {
             delCategory = db.Categories.Find(idElement1);
             db.Categories.Remove(delCategory);
             db.SaveChanges();
         }
         return(new Response <Category>(null, delCategory.IdCategory, true, null));
     }
     catch (Exception err)
     {
         return(new Response <Category>(err, null, false, null));
     }
 }
Exemple #7
0
 public Response <Artist> Delete(int idElement1, int idElement2 = 0)
 {
     try
     {
         Artist delPerson;
         using (TTDBEntities db = new TTDBEntities())
         {
             delPerson = db.Artists.Find(idElement1);
             db.Artists.Remove(delPerson);
             db.SaveChanges();
         }
         return(new Response <Artist>(null, delPerson.IdArtist, true, null));
     }
     catch (Exception err)
     {
         return(new Response <Artist>(err, null, false, null));
     }
 }
Exemple #8
0
 public Response <Artist> Update(Artist element)
 {
     try
     {
         Artist updatePerson;
         using (TTDBEntities db = new TTDBEntities())
         {
             updatePerson = db.Artists.Find(element.IdArtist);
             if (element.FullName != null)
             {
                 updatePerson.FullName = element.FullName;
             }
             else if (element.BirthDate != null)
             {
                 updatePerson.BirthDate = element.BirthDate;
             }
             else if (element.StartDate != null)
             {
                 updatePerson.StartDate = element.StartDate;
             }
             else if (element.Email != null)
             {
                 updatePerson.Email = element.Email;
             }
             else if (element.PhoneNumber != null)
             {
                 updatePerson.PhoneNumber = element.PhoneNumber;
             }
             else if (element.Address != null)
             {
                 updatePerson.Address = element.Address;
             }
             db.Entry(updatePerson);
             db.SaveChanges();
         }
         return(new Response <Artist>(null, updatePerson.IdArtist, true, null));
     }
     catch (Exception err)
     {
         return(new Response <Artist>(err, null, false, null));
     }
 }
Exemple #9
0
 public Response <Artists_Categories> Update(Artists_Categories element)
 {
     try
     {
         Artists_Categories updatePerson_Category;
         using (TTDBEntities db = new TTDBEntities())
         {
             updatePerson_Category = db.Artists_Categories.Find(element.IdArtist, element.IdCategory);
             if (element.Observation != null)
             {
                 updatePerson_Category.Observation = element.Observation;
             }
             db.Entry(updatePerson_Category);
             db.SaveChanges();
         }
         return(new Response <Artists_Categories>(null, updatePerson_Category.IdCategory, true, null));
     }
     catch (Exception err)
     {
         return(new Response <Artists_Categories>(err, null, false, null));
     }
 }