コード例 #1
0
ファイル: DBManagement.cs プロジェクト: jorge-lopez/Launch
 //Metodo que agrega comments a una aplicacion
 public static bool AddComment(CUSTOMER customer, APP app, string _content)
 {
     using (var dbContext = new LAUNCHEntities())
     {
         var comment = new COMMENT
         {
             ID_Customer = customer.ID_Customer,
             ID_App = app.ID_App,
             Date = DateTime.Now,
             Content = _content
         };
         dbContext.COMMENTs.Add(comment);
         var changesSaved = dbContext.SaveChanges();
         return changesSaved >= 1;
     }
 }
コード例 #2
0
ファイル: DBManagement.cs プロジェクト: jorge-lopez/Launch
        //Metodo que agrega un Customer a la base de datos
        public static bool AddCustomer(string _FirstName, string _LastName, string _Email, string _Password)
        {
            try
            {
                using (var dbContext = new LAUNCHEntities())
                {
                    dbContext.Database.Connection.Open();
                    //verifica si ya existe un customer en la base de datos con ese email
                    var Existent = (from c in dbContext.CUSTOMERs
                                    where c.Email == _Email
                                    select c).Any();
                    //tira una excepcion si ya existe, y si no, agrega al customer a la base y lo guarda
                    if (Existent == true)
                    {
                        throw new InvalidOperationException("Ya existe un usuario con ese correo. Escoge otro");
                    }

                    var customer = new CUSTOMER
                    {
                        FirstName = _FirstName,
                        LastName = _LastName,
                        Email = _Email,
                        Password = _Password
                    };
                    dbContext.CUSTOMERs.Add(customer);
                    var changesSaved = dbContext.SaveChanges();
                    return changesSaved >= 1;

                }
            }
            catch (Exception ex)
            {
                string error = ex.Message;
                return false;
            }
        }