public IHttpActionResult Create([FromBody] OperatorDTO _operator) { string accessType = ""; ThrowIfUserHasNoRole(accessType); if (_operator == null) { throw new KairosException("Missing model parameter"); } if (_operator.Operator_PK != 0) { throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) ."); } using (var _operatorCreateHandler = new OperatorCreateHandler(Db, ActiveUser, new OperatorValidator(), new OperatorFactory(Db, ActiveUser), new OperatorQuery(Db), AccessControl)) { using (var transaction = new TransactionScope()) { var saveResult = _operatorCreateHandler.Save(_operatorDTO: _operator, dateStamp: DateTime.Now); transaction.Complete(); if (saveResult.Success) { return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message))); } return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message))); } } }
public void Update(OperatorDTO _operatorDTO, DateTime dateStamp) { if (_operatorDTO == null) { throw new ArgumentNullException("Operator model is null."); } tblM_Operator _operator = _operatorFactory.CreateFromDbAndUpdateFromDTO(_operatorDTO, dateStamp); }
public tblM_Operator Insert(OperatorDTO _operatorDTO, DateTime dateStamp) { if (_operatorDTO == null) { throw new ArgumentNullException("Operator model is null."); } tblM_Operator _operator = _operatorFactory.CreateFromDTO(_operatorDTO, dateStamp); return(Db.tblM_Operator.Add(_operator)); }
private OperatorEntryModel GetCreateStateModel() { OperatorEntryFormData formData = new OperatorEntryFormData(); List <Control> formControls = CreateFormControls(0); OperatorDTO _operatorDTO = new OperatorDTO(); return(new OperatorEntryModel() { FormData = formData, FormControls = formControls, Model = new OperatorDTO(), }); }
private OperatorEntryModel GetUpdateStateModel(int _operatorPK) { OperatorEntryFormData formData = new OperatorEntryFormData(); List <Control> formControls = CreateFormControls(_operatorPK); OperatorDTO _operatorDTO = _operatorQuery.GetByPrimaryKey(_operatorPK); if (_operatorDTO == null) { throw new KairosException($"Record with primary key '{_operatorDTO.Operator_PK}' is not found."); } return(new OperatorEntryModel() { FormData = formData, FormControls = formControls, Model = _operatorDTO, }); }
/// <summary> /// 同步写操作日志 /// </summary> /// <param name="sn"></param> /// <param name="operation"></param> /// <param name="message"></param> /// <param name="user"></param> /// <param name="commit"></param> public static void RecordOperation(string sn, string operation, string message, UserDTO user = null, bool commit = false) { if (sn.IsNullOrBlank()) { throw new Exception("sn can not be empty"); } if (sn == Guid.Empty.ToString()) { throw new Exception("sn can not be Guid.Empty"); } var ip = HttpHelper.GetRealIP(); OperatorDTO @operator = null; if (user == null) { @operator = GetCurrentOperator(); } else { @operator = new OperatorDTO() { UserId = user.Id, OperatorName = user.Name }; } var record = new OperateRecordDTO() { Sn = sn, UserId = @operator.UserId == Guid.Empty ? (Guid?)null : @operator.UserId, OperatorName = @operator.OperatorName, Operation = operation, Message = message, Ip = ip }; SaveOperateRecord(record, commit); }
public SaveResult <OperatorEntryModel> Save(OperatorDTO _operatorDTO, DateTime dateStamp) { ModelValidationResult validationResult = _operatorValidator.Validate(_operatorDTO); bool success = false; OperatorEntryModel model = null; if (validationResult.IsValid) { success = true; Update(_operatorDTO, dateStamp); Db.SaveChanges(); model = _operatorEntryDataProvider.Get(_operatorDTO.Operator_PK); } return(new SaveResult <OperatorEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
public OperatorDTO GetByTitle(string title) { OperatorDTO record = GetQuery().FirstOrDefault(_operator => _operator.Title == title); return(record); }
public OperatorDTO GetByPrimaryKey(int primaryKey) { OperatorDTO record = GetQuery().FirstOrDefault(_operator => _operator.Operator_PK == primaryKey); return(record); }