Пример #1
0
        private RefoodUserDTO Update(RefoodUserViewModel viewModel)
        {
            try
            {
                log.Debug(RefoodUserViewModel.FormatRefoodUserViewModel(viewModel));

                // get
                log.Debug("_refoodUserService.GetRefoodUser - refoodUserId: " + viewModel.RefoodUserId + " ");

                var existingRefoodUser = _refoodUserService.GetRefoodUser(viewModel.RefoodUserId);

                log.Debug("_refoodUserService.GetRefoodUser - " + RefoodUserDTO.FormatRefoodUserDTO(existingRefoodUser));

                if (existingRefoodUser != null)
                {
                    // copy values
                    existingRefoodUser.Username  = viewModel.Username;
                    existingRefoodUser.Fullname  = viewModel.Fullname;
                    existingRefoodUser.Email     = viewModel.Email;
                    existingRefoodUser.Active    = viewModel.Active;
                    existingRefoodUser.IsDeleted = viewModel.IsDeleted;

                    // audit
                    //existingRefoodUser.UpdateBy = UserInfo.UserID;
                    existingRefoodUser.UpdateOn = DateTime.UtcNow;

                    // update
                    log.Debug("_refoodUserService.UpdateRefoodUser - " + RefoodUserDTO.FormatRefoodUserDTO(existingRefoodUser));

                    _refoodUserService.UpdateRefoodUser(existingRefoodUser);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingRefoodUser: null, RefoodUserId: " + viewModel.RefoodUserId);
                }

                return(existingRefoodUser);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Пример #2
0
        private RefoodUserDTO Create(RefoodUserViewModel viewModel)
        {
            try
            {
                log.Debug(RefoodUserViewModel.FormatRefoodUserViewModel(viewModel));

                RefoodUserDTO refoodUser = new RefoodUserDTO();

                // copy values
                refoodUser.RefoodUserId = viewModel.RefoodUserId;
                refoodUser.Username     = viewModel.Username;
                refoodUser.Fullname     = viewModel.Fullname;
                refoodUser.Email        = viewModel.Email;
                refoodUser.Active       = viewModel.Active;
                refoodUser.IsDeleted    = viewModel.IsDeleted;


                // audit
                //refoodUser.CreateBy = UserInfo.UserID;
                //refoodUser.UpdateBy = UserInfo.UserID;
                refoodUser.CreateOn = DateTime.UtcNow;
                refoodUser.UpdateOn = DateTime.UtcNow;

                // add
                log.Debug("_refoodUserService.AddRefoodUser - " + RefoodUserDTO.FormatRefoodUserDTO(refoodUser));

                int id = _refoodUserService.AddRefoodUser(refoodUser);

                refoodUser.RefoodUserId = id;

                log.Debug("result: 'success', id: " + id);

                return(refoodUser);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Пример #3
0
        //[ValidateAntiForgeryToken]
        public JsonResult SaveList(RefoodUserViewModel[] viewModels, int?itemId)
        {
            try
            {
                log.Debug("SaveList");

                if (viewModels != null)
                {
                    // save list
                    foreach (RefoodUserViewModel viewModel in viewModels)
                    {
                        log.Debug(RefoodUserViewModel.FormatRefoodUserViewModel(viewModel));

                        if (viewModel.RefoodUserId > 0)
                        {
                            var t = Update(viewModel);
                        }
                        else
                        {
                            var t = Create(viewModel);
                        }
                    }
                }
                else
                {
                    log.Error("viewModels: null");
                }

                return(Json(true));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Пример #4
0
        public ActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_refoodUserService.GetRefoodUser - refoodUserId: " + id + " ");

                var refoodUser = new RefoodUserViewModel(_refoodUserService.GetRefoodUser(id));

                log.Debug("_refoodUserService.GetRefoodUser - " + RefoodUserViewModel.FormatRefoodUserViewModel(refoodUser));

                log.Debug("result: 'success'");

                //return Json(refoodUser, JsonRequestBehavior.AllowGet);
                return(Content(JsonConvert.SerializeObject(refoodUser), "application/json"));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }