public IHttpActionResult Create([FromBody] AsetDTO aset) { ThrowIfUserHasNoRole(createRole); if (aset == null) { throw new KairosException("Missing model parameter"); } if (aset.Aset_PK != 0) { throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) ."); } using (var asetCreateHandler = new AsetCreateHandler(Db, ActiveUser, new AsetValidator(), new AsetFactory(Db, ActiveUser), new AsetQuery(Db), AccessControl)) { using (var transaction = new TransactionScope()) { var saveResult = asetCreateHandler.Save(asetDTO: aset, 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(AsetDTO asetDTO, DateTime dateStamp) { if (asetDTO == null) { throw new ArgumentNullException("Aset model is null."); } tblM_Aset aset = asetFactory.CreateFromDbAndUpdateFromDTO(asetDTO, dateStamp); }
public AsetDTO GetByPrimaryKey(int primaryKey) { AsetDTO record = GetQuery().FirstOrDefault(aset => aset.Aset_PK == primaryKey); GetPhoto(record); return(record); }
public tblM_Aset Insert(AsetDTO asetDTO, DateTime dateStamp) { if (asetDTO == null) { throw new ArgumentNullException("Aset model is null."); } tblM_Aset aset = asetFactory.CreateFromDTO(asetDTO, dateStamp); return(Db.tblM_Aset.Add(aset)); }
private void GetPhoto(AsetDTO record) { if (record != null) { var aset = Db.tblM_Aset.Find(record.Aset_PK); if (aset != null) { record.FilePhotoInBase64 = new WebImageConverter().GetBase64FromBytes(aset.FilePhoto); } } }
private AsetEntryModel GetCreateStateModel() { AsetEntryFormData formData = new AsetEntryFormData(); List <Control> formControls = CreateFormControls(0); AsetDTO asetDTO = new AsetDTO(); return(new AsetEntryModel() { FormData = formData, FormControls = formControls, Model = new AsetDTO(), }); }
private AsetEntryModel GetUpdateStateModel(int asetPK) { AsetEntryFormData formData = new AsetEntryFormData(); List <Control> formControls = CreateFormControls(asetPK); AsetDTO asetDTO = asetQuery.GetByPrimaryKey(asetPK); if (asetDTO == null) { throw new KairosException($"Record with primary key '{asetDTO.Aset_PK}' is not found."); } formData.AsetKategoris = GetAsetKategoris(asetDTO.KategoriAset_FK); return(new AsetEntryModel() { FormData = formData, FormControls = formControls, Model = asetDTO, }); }
public SaveResult <AsetEntryModel> Save(AsetDTO asetDTO, DateTime dateStamp) { ModelValidationResult validationResult = asetValidator.Validate(asetDTO); bool success = false; AsetEntryModel model = null; if (validationResult.IsValid) { success = true; Update(asetDTO, dateStamp); Db.SaveChanges(); model = asetEntryDataProvider.Get(asetDTO.Aset_PK); } return(new SaveResult <AsetEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }