Beispiel #1
0
        private void Save()
        {
            string message = "";

            try
            {
                var validator = NinjectBinder.GetValidator <TimeZoneViewModelValidator>();
                var results   = validator.Validate(this);
                if (!results.IsValid)
                {
                    message = string.Join("\n", results.Errors);
                    SendMessage(message);
                    return;
                }

                CurrentTimeZone.TimeZoneName          = Name;
                CurrentTimeZone.TimeZoneCode          = Code;
                CurrentTimeZone.Status                = GeneralStatus.Enabled;
                CurrentTimeZone.TimeGroupAssociations = GetTimeGroupAssociations();

                if (CurrentTimeZone.TimeZoneID == 0)
                {
                    CurrentTimeZone.CreateUserID = ApplicationManager.GetInstance().CurrentOperatorInfo.OperatorID;
                    CurrentTimeZone.CreateDate   = DateTime.Now;
                    CurrentTimeZone = _timeZoneRepo.Insert(CurrentTimeZone);
                    message         = "增加时间区成功!";
                }
                else
                {
                    CurrentTimeZone.UpdateUserID = ApplicationManager.GetInstance().CurrentOperatorInfo.OperatorID;
                    CurrentTimeZone.UpdateDate   = DateTime.Now;
                    _timeZoneRepo.Update(CurrentTimeZone);
                    message = "修改时间区成功!";
                }
            }
            catch (BusinessException ex)
            {
                Log.Error("Update timezone fails.", ex);
                SendMessage(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Log.Error("Update timezone fails.", ex);
                message = "保存时间区失败";
                SendMessage(message);
                return;
            }

            ViewModelAttachment.CoreModel            = CurrentTimeZone;
            ViewModelAttachment.LastOperationSuccess = true;
            RaisePropertyChanged(null);
            Close(message);
        }