public async Task <ApiResult <string> > ModifyAsync(EditBabyViewModel parm)
        {
            var res = new ApiResult <string>();

            try
            {
                int  user_id = Config.userid();
                Baby baby    = parm as Baby;
                baby.updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //更新宝宝信息
                await Db.Updateable(baby).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();

                //更新用户级联表
                await Db.Updateable <BabyUser>().SetColumns(it => new BabyUser()
                {
                    identity = parm.identity
                })
                .Where(it => it.baby_id == parm.id && it.user_id == user_id).ExecuteCommandAsync();
            }
            catch (Exception ex)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error + ex.Message;
            }
            return(res);
        }
        public async Task <ApiResult <string> > AddAsync(EditBabyViewModel parm)
        {
            var res = new ApiResult <string>();

            try
            {
                int  user_id = Config.userid();
                Baby baby    = parm as Baby;
                baby.founder_id = user_id;
                baby.createdOn  = baby.updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                baby.avatar_url = string.IsNullOrEmpty(baby.avatar_url) ? "uploads/default_baby-avatar.png" : baby.avatar_url;
                baby            = await Db.Insertable(baby).ExecuteReturnEntityAsync();//插入宝宝表,返回实体

                var link = new BabyUser
                {
                    baby_id   = baby.id,
                    user_id   = user_id,
                    identity  = parm.identity,
                    createdOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                };
                await Db.Insertable(link).ExecuteCommandAsync();//插入宝宝-用户关联表
            }
            catch (Exception ex)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error + ex.Message;
            }
            return(res);
        }
        public EditBabyPage(Baby baby)
        {
            var editBabyViewModel = new EditBabyViewModel();

            editBabyViewModel.Baby = baby;

            BindingContext = editBabyViewModel;

            InitializeComponent();

            //var editBabyViewModel = BindingContext as EditBabyViewModel;

            //editBabyViewModel.Baby = baby;
        }
Example #4
0
        public async Task <IActionResult> modifyBaby(EditBabyViewModel parm)
        {
            var res = await _babyService.ModifyAsync(parm);

            return(Ok(res));
        }