コード例 #1
0
ファイル: BackerService.cs プロジェクト: gdstathis/Crowdfund
        public bool UpdateBackerOptions(int id, UpdateBackerOptions options)
        {
            if (id <= 0)
            {
                return(false);
            }
            if (options == null)
            {
                return(false);
            }
            var Backer = context.Set <Backer>().SingleOrDefault(p => p.Id == id);

            if (Backer == null)
            {
                Console.WriteLine("Does not exist baker with this id");
                return(false);
            }

            if (options.Firstname != null)
            {
                Backer.Firstname = options.Firstname;
            }

            if (options.Lastname != null)
            {
                Backer.Lastname = options.Lastname;
            }

            if (options.Phone != null)
            {
                Backer.Phone = options.Phone;
            }

            if (options.Email != null)
            {
                Backer.Email = options.Email;
            }

            if (options.NewDonate <= 0)
            {
                Backer.Donate = options.NewDonate;
            }

            context.Update(Backer);
            try {
                context.SaveChanges();
                Console.WriteLine("Update ok");
            } catch (Exception ex) {
                Console.WriteLine("UPDATE FAIL" + ex);
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public void UpdateBacker_Success()
        {
            var options = new UpdateBackerOptions()
            {
                Firstname = "Giannis",
                Lastname  = "papadopoulos",
                Email     = "afafadfsdfsd",
                Phone     = "fsdfsdfsdfwef3"
            };
            var success = bcsv_.UpdateBackerOptions(1, options);

            Assert.True(success);
        }