/// <summary> /// Inserts the data into the database. /// </summary> /// <param name="db">The database connection to be used</param> /// <param name="item">Data which need to be inserted</param> /// <returns>Returns null if insert fails else returns data in DynamicDictionary</returns> public virtual ResponseModel Insert(DbConnect con, DynamicDictionary item) { ResponseModel resp = new ResponseModel(false, string.Empty); TModel model = new TModel(); try { //validate data before saving if (!IsValid((DynamicDictionary)item.Clone(), false, con)) { resp.message = "Validation failed."; resp.PushValidationErrors(ValidationErrors); return(resp); } //save if (CrudRepo.Insert(con, item)) { if (LoadItemAfterSave) { //PropertyInfo key = Models.ModelService.GetKeyPropertyInfo(item); //TKey id = Models.ModelService.ChangeType<TKey>(key.GetValue(item)); //CrudSrvc.get //item = CrudSrvc.GetItemAsModel(id); resp.data = item; } resp.success = true; resp.message = "Data added successfully."; } else { resp.message = "System Error :: DB"; } } catch (Exception ex) { Errors.Add(ex.Message); } if (resp.success == false) { resp.PushErrors(CrudRepo.Errors); resp.PushErrors(Errors); resp.PushValidationErrors(ValidationErrors); } return(resp); }