示例#1
0
        public static void SaveImage(ImageModel image)
        {
            using (var context = new ImageStoreEntities())
            {
                try
                {
                    var id     = (short)(context.Images.Any() ? context.Images.Max(x => x.Id) + 1 : 0);
                    var images = context.Images.Add(new Image
                    {
                        Id          = id,
                        Created     = DateTime.Now,
                        Description = image.Description,
                        Title       = image.Title,
                        Path        = image.Path,
                        UserId      = image.UserId,
                    });

                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.Message);
                }
            }
        }
示例#2
0
        public static void UpdateUser(UserModel user)
        {
            using (var context = new ImageStoreEntities())
            {
                try
                {
                    var dbUser = context.Users.Where(u => u.Id == user.Id).Single();

                    dbUser.UserName = user.Username;
                    dbUser.Password = user.Password;

                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.Message);
                }
            }
        }
示例#3
0
        public static void SaveUser(UserModel User)
        {
            using (var context = new ImageStoreEntities())
            {
                try
                {
                    var id = (short)(context.Users.Any() ? context.Users.Max(x => x.Id) + 1 : 0);
                    context.Users.Add(new User
                    {
                        Id       = id,
                        UserName = User.Username,
                        Password = User.Password,
                    });

                    context.SaveChanges();
                }catch (Exception e)
                {
                    Trace.WriteLine(e.Message);
                }
            }
        }