public void CreateUser(User data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            context.Users.InsertOnSubmit(data);
            context.SubmitChanges();
        }
        public void RegisterUser(UserModel user)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();
            User DBuser = new User();

            if (context.Users.SingleOrDefault(u => u.email == user.email) == null)
            {
                DBuser.accountnumber = user.accountnumber;
                DBuser.balance = 0;
                DBuser.city = user.city;
                DBuser.email = user.email;
                DBuser.name = user.name;
                DBuser.password = user.password;
                DBuser.status = "active";

                context.Users.Add(DBuser);

                context.SaveChanges();
            }
        }
 partial void DeleteUser(User instance);
 partial void UpdateUser(User instance);
 partial void InsertUser(User instance);
        public void UpdateUser(User data)
        {
            DatabaseDataContext context = new DatabaseDataContext();

            User user = context.Users.Where(u => u.UserID == data.UserID).SingleOrDefault();
            user.Biography = data.Biography;
            user.EmailAddress = data.EmailAddress;
            user.Location = data.Location;
            user.Name = data.Name;
            user.Password = data.Password;
            user.ProfilePictureID = data.ProfilePictureID;
            user.Username = data.Username;

            context.SubmitChanges();
        }
Ejemplo n.º 7
0
 public string Register(string nickname, string password, string firstName, string lastName, string info)
 {
     if (_db.User.Any() && _db.User.Any(u => u.Nickname == nickname))
         return JsonConvert.SerializeObject(new JsonResult("another user have the same nickname"));
     User user = new User
     {
         Nickname = nickname,
         Password = password,
         FirstName = firstName,
         LastName = lastName,
         Info = info,
         ID = Guid.NewGuid()
     };
     JsonResult jsonResult;
     try
     {
         _db.User.Add(user);
         _db.SaveChanges();
     }
     catch (Exception)
     {
         jsonResult = new JsonResult("unknown error occured while adding a new record in data base");
         return JsonConvert.SerializeObject(jsonResult);
     }
     jsonResult = new JsonResult(new List<Dictionary<string, object>>());
     return JsonConvert.SerializeObject(jsonResult);
 }