Пример #1
0
        public IHttpActionResult PuttblUserData(int id, tblUserData tblUserData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblUserData.ID)
            {
                return(BadRequest());
            }

            db.Entry(tblUserData).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblUserDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
 public Boolean Delete(User user)
 {
     _context.Users.Remove(user);
     _context.SaveChanges();
     _logger.LogInformation("Delete Task Group " + user.UserId + " " + user.FirstName);
     return(true);
 }
Пример #3
0
        /// <summary>
        /// 创建新用户
        /// </summary>
        /// <param name="data">用户数据</param>
        /// <returns>新用户ID</returns>
        public async Task <int> CreateUserAsync([NotNull] PureUserData data)
        {
            UserCreateRequest request = new UserCreateRequest
            {
                Connection  = configuration.GetAuth0Config(ConfigurationKeyConstants.Auth0Connection),
                Email       = data.Email,
                PhoneNumber = data.PhoneNumber
            };

            User user = await userClient.CreateAsync(request);

            if (user == null)
            {
                return(-1);
            }

            int nextId = dataContext.UserDatas.Select((data) => data.ID).Max() + 1;

            // 获取可用身份列表
            Role[] availableRoles = await roleGetter.GetAvailableRoles();

            // 去除重复项与不在身份列表内的项
            string[] roles = data.Role.Split(' ').Distinct()
                             .Where((name) => availableRoles.Any((role) => role.Name == name)).ToArray();

            await userClient.AssignRolesAsync(user.UserId, new AssignRolesRequest { Roles = roles });

            data.Role = roles.Aggregate((r1, r2) => r1 + ' ' + r2);

            dataContext.Add <UserData>(data.ToUserData(nextId, user.UserId));
            dataContext.SaveChanges();
            return(nextId);
        }
Пример #4
0
 public Boolean Delete(TaskGroup taskGroup)
 {
     _context.TaskGroups.Remove(taskGroup);
     _context.SaveChanges();
     _logger.LogInformation("Delete Task Group " + taskGroup.TaskGroupId + " " + taskGroup.Name);
     return(true);
 }
Пример #5
0
 public Boolean Delete(UserTask userTask)
 {
     _context.UserTasks.Remove(userTask);
     _context.SaveChanges();
     _logger.LogInformation("Delete Task Group " + userTask.UserTaskId + " " + userTask.Name);
     return(true);
 }
Пример #6
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,BirthDay,Job,Address")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Пример #7
0
        public ActionResult Create([Bind(Include = "userID,firstName,lastName,userName,email,joined")] User user)
        {
            if (ModelState.IsValid)
            {
                user.joined = DateTime.Now;
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Пример #8
0
        public ActionResult Create([Bind(Include = "ID,Name,Price")] UserData userData)
        {
            if (ModelState.IsValid)
            {
                userData.PriceinWord = AmountInWords.ConvertToWords(userData.Price);
                db.Users.Add(userData);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userData));
        }
Пример #9
0
 public bool AddUser(User user)
 {
     try
     {
         db.Users.Add(user);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message);
         return(false);
     }
 }
Пример #10
0
        public int SaveProfile(MySettingsViewModel Data)
        {
            using (UserDataContext db = new UserDataContext())
            {
                var User = db.tblUserData.Single(o => o.UserName.Equals(Data.UserName));
                if (Data.ConfirmPassword == User.UserPassword)
                {
                    User.UserName  = Data.UserName;
                    User.Email     = Data.Email;
                    User.FirstName = Data.FirstName;
                    User.LastName  = Data.LastName;
                    User.Gender    = Data.Gender;
                    User.BirthDate = Data.BirthDate;

                    var Address = db.tblAddress.Single(o => o.ID.Equals(User.AddressID));
                    Address.Country         = Data.Country;
                    Address.City            = Data.City;
                    Address.Region          = Data.Region;
                    Address.ZipCode         = Data.ZipCode;
                    Address.Street          = Data.Street;
                    Address.Number          = Data.Number;
                    Address.ApartmentNumber = Data.ApartmentNumber;

                    db.SaveChanges();
                    return(0);
                }

                else
                {
                    return(1);
                }
            }
        }
Пример #11
0
        public void PlaceBet(string teams, string formula, double coefficient, int id, double price, DateTime date)
        {
            using (UserDataContext db = new UserDataContext())
            {
                BetEntity bet = new BetEntity();

                bet.Holder = db.Users.Find(id);

                if (bet.Holder.Cash >= price)
                {
                    db.Users.Find(id).Cash -= price;
                }
                else
                {
                    throw new NotEnoughMoneyUserClientException("Недостаточно средств!");
                }


                bet.Date     = date;
                bet.Coeff    = coefficient;
                bet.Teams    = teams;
                bet.Formula  = formula;
                bet.BetPrice = price;


                db.Bets.Add(bet);
                db.SaveChanges();
            }

            MessageBox.Show("Готово!");
        }
Пример #12
0
        public void AddUser(string FirstName, string SecondName, string Email, string Password)
        {
            if (FirstName == string.Empty || SecondName == string.Empty || Email == string.Empty || Password == string.Empty)
            {
                throw new EmptyParameterException("Заполните все данные!");
            }

            using (UserDataContext db = new UserDataContext())
            {
                if (db.Users.FirstOrDefault(row => row.Email == Email) == null)
                {
                    UserEntity user = new UserEntity();

                    user.FirstName  = FirstName;
                    user.SecondName = SecondName;
                    user.Email      = Email;
                    user.Password   = Password;
                    user.UserStatus = "User";
                    user.Cash       = 10;

                    db.Users.Add(user);
                    db.SaveChanges();
                }
                else
                {
                    throw new AlreadyExistsUserClientException("Пользователь с таким адресом уже существует!");
                }
            }
        }
Пример #13
0
 public void Create(string roleName)
 {
     _context.Roles.Add(new RoleEntity {
         Name = roleName
     });
     _context.SaveChanges();
 }
Пример #14
0
        public IActionResult Create([FromBody] UserData data)
        {
            if (data == null)
            {
                return(BadRequest());
            }

            var item = _UserDataContext.UserDatas.OrderByDescending(x => x.ID).FirstOrDefault();

            data.ID         = item.ID + 1;
            data.CreateTime = DateTime.Now;

            _UserDataContext.UserDatas.Add(data);
            _UserDataContext.SaveChanges();

            return(CreatedAtRoute("GetUser", new { id = data.ID }, data));
        }
Пример #15
0
        public Chart Index(UserData udInput)
        {
            if (ModelState.IsValid)
            {
                Point pt = new Point {
                    ChartId = p
                };
                p++;
                int n = (udInput.RangeTo - udInput.RangeFrom) / (int)udInput.step;
                px = new int[n + 1];
                py = new int[n + 1];
                int i;
                for (i = 0, pt.PointX = udInput.RangeFrom; pt.PointX <= udInput.RangeTo; pt.PointX += (int)udInput.step, i++)
                {
                    pt.PointY = udInput.a * (pt.PointX * pt.PointX) + udInput.b * pt.PointX + udInput.c;
                    px[i]     = pt.PointX;
                    py[i]     = pt.PointY;
                    db.Points.Add(pt);
                    db.SaveChanges();
                }

                // добавляем информацию о графике в базу данных
                db.UserDatas.Add(udInput);
                // сохраняем в бд все изменения
                db.SaveChanges();

                title = "y = " + udInput.a + "x^2 + " + udInput.b + "x + " + udInput.c;

                return(new Chart(600, 400, ChartTheme.Blue)
                       .AddTitle("y = ax^2 + bx + c")
                       .AddLegend()
                       .AddSeries(
                           name: title,
                           chartType: "Spline", //not Line :)
                           xValue: px,
                           yValues: py)
                       .Write(format: "png"));
            }
            else
            {
                return(new Chart(300, 300, ChartTheme.Blue)
                       .AddTitle("Sorry, your data is not valid :( ")
                       .Write(format: "png"));
            }
        }
Пример #16
0
 public void TraceError(string title, string message, SeverityLevel severityLevel)
 {
     using (var context = new UserDataContext()){
         context.TraceMessage.Add(
             new TraceMessage(title, message, severityLevel, DateTime.UtcNow)
             );
         context.SaveChanges();
     }
 }
Пример #17
0
 /// <summary>
 /// 释放由当前对象占有的所有资源。
 /// </summary>
 public void Dispose()
 {
     if (!m_readonly)
     {
         m_context.SaveChanges();
     }
     m_context.Dispose();
     m_disposed = true;
 }
Пример #18
0
 public void PurchaseProduct(int userId, int productId)
 {
     using (var context = new UserDataContext()){
         var product = context.Products.Find(productId);
         product.OwnerId     = userId;
         product.IsPurchased = true;
         context.SaveChanges();
     }
 }
Пример #19
0
 public void ChangeGroupName(int id, string name)
 {
     using (var db = new UserDataContext())
     {
         var group = db.Groups.Find(id);
         if (group != null)
         {
             group.Name = name;
             db.SaveChanges();
         }
     }
 }
Пример #20
0
 public void Remove(DictionaryType type, int id)
 {
     using (var db = new UserDataContext())
     {
         var history = db.Histories.FirstOrDefault(t => t.Type == type && t.Id == id);
         if (history != null)
         {
             db.Histories.Remove(history);
             db.SaveChanges();
         }
     }
 }
Пример #21
0
        public bool AddNewProduct(Product product)
        {
            using (var context = new UserDataContext()){
                if (DoesProductExist(product.ProductName) || product == null)
                {
                    return(false);
                }

                context.Products.Add(product);
                context.SaveChanges();
                return(true);
            }
        }
Пример #22
0
 public void Save(List <LogDTO> logDTO)
 {
     try
     {
         _context.Set <LogDTO>().AddRange(logDTO);
         _context.ChangeTracker.DetectChanges();
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("{0} Exception caught.", e);
     }
 }
Пример #23
0
 public void DeleteGroup(int id)
 {
     using (var db = new UserDataContext())
     {
         var group = new Group()
         {
             Id = id
         };
         db.Groups.Attach(group);
         db.Groups.Remove(group);
         db.SaveChanges();
     }
 }
Пример #24
0
        public bool SaveUser(User user)
        {
            using (var context = new UserDataContext()){
                if (DoesUserExist(user.UserId, context))
                {
                    return(false);
                }

                context.Users.Add(user);
                context.SaveChanges();
            }
            return(true);
        }
Пример #25
0
        public IActionResult Create(UserInfo ui)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            ui.TodayDate = DateTime.Now;

            _db.Posts.Add(ui);
            _db.SaveChanges();

            return(View());
        }
Пример #26
0
 private void Add(object sender, RoutedEventArgs e)
 {
     using (var context = new UserDataContext())
     {
         context.userData.Add(new UserData()
         {
             Id        = ++id,
             Email     = Email.Text,
             FirstName = txtBxName.Text,
             LastName  = txtBxLastName.Text,
         });
         context.SaveChanges();
     }
 }
Пример #27
0
        public bool DeleteUser(int userId)
        {
            using (var context = new UserDataContext()){
                if (!DoesUserExist(userId, context))
                {
                    return(false);
                }

                var user = context.Users.SingleOrDefault(u => u.UserId == userId);
                context.Users.Remove(user);
                context.SaveChanges();
            }
            return(true);
        }
Пример #28
0
        public UserEntity Create(UserEntity user, string password, string userRole = "user")
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new AppException("Username \"" + user.Username + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.Roles.Add(userRole);

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
Пример #29
0
        public UserController(UserDataContext userDataContext)
        {
            _UserDataContext = userDataContext;

            if (_UserDataContext.UserDatas.Count() == 0)
            {
                _UserDataContext.UserDatas.Add(new UserData {
                    ID         = 1,
                    Name       = "Vacvin",
                    Birthday   = DateTime.Parse("1982/01/01"),
                    CreateTime = DateTime.Now
                });
                _UserDataContext.SaveChanges();
            }
        }
        public IActionResult Get()
        {
            if (_userDataContext.Users.ToList().Count == 0)
            {
                List <UserData> udata = new List <UserData>();
                udata.Add(new UserData {
                    Email = "*****@*****.**", Name = "Ahmet", Password = "******"
                });
                udata.Add(new UserData {
                    Email = "*****@*****.**", Name = "Tarik", Password = "******"
                });
                udata.Add(new UserData {
                    Email = "*****@*****.**", Name = "Veli", Password = "******"
                });
                udata.Add(new UserData {
                    Email = "*****@*****.**", Name = "Ali", Password = "******"
                });
                _userDataContext.Users.AddRange(udata);
                _userDataContext.SaveChanges();
            }
            var usersData = _userDataContext.Users.ToList();

            return(Ok(usersData));
        }